Skip to content

[FIX] local: fix SQL restore - unaccent IMMUTABLE detection and missing odoo role#169

Draft
ikcha-odoo wants to merge 2 commits into
odoo-odev:mainfrom
ikcha-odoo:fix/sql-restore-immutable-role
Draft

[FIX] local: fix SQL restore - unaccent IMMUTABLE detection and missing odoo role#169
ikcha-odoo wants to merge 2 commits into
odoo-odev:mainfrom
ikcha-odoo:fix/sql-restore-immutable-role

Conversation

@ikcha-odoo

Copy link
Copy Markdown

Problem

Restoring SQL dumps (e.g. odev restore <db> <file>.zip) consistently failed with:

[-] Failed to restore dump, the psql process exited unexpectedly with error:
    ERROR:  functions in index expression must be marked IMMUTABLE
[!] Retrying in degraded mode (slower and ignoring errors)

Two bugs caused this, and fixing the first exposed the second.

Fix 1 — _buffered_sql_enable_extensions: broken for...else logic

odev pre-installs an IMMUTABLE public.unaccent(text) wrapper before restoring when the dump doesn't already define one (PostgreSQL's built-in unaccent is STABLE, which is rejected in index expressions).

The detection used a for...else that only called unaccent() when the loop completed without break. But the loop also breaks when the line-limit (SQL_DUMP_IGNORE_LINES_NUMBER = 100) is reached — so for any real dump longer than 100 lines that lacks an IMMUTABLE wrapper in its header, the loop exited via the limit break and unaccent() was silently skipped.

Fix: explicit immutable_defined flag; unaccent() is called whenever the marker isn't found within the scanned header.

Fix 2 — ensure_roles(): missing odoo role aborts fast-mode restore

Once fix 1 kept the restore in fast mode (--single-transaction -v ON_ERROR_STOP=1), a new error surfaced: Odoo dumps commonly end with GRANT CREATE ON SCHEMA public TO odoo. With ON_ERROR_STOP=1, a missing local odoo role caused the entire transaction to roll back, leaving an empty database.

Previously this was hidden because the IMMUTABLE error forced degraded mode (errors ignored), which silently swallowed the GRANT failure and still loaded the data.

Fix: added ensure_roles() (modeled on unaccent()) that pre-creates the conventional odoo role before each SQL restore, keeping those GRANT statements valid.

Also included

  • clone.py / connectors/git.py: wrap clone/checkout in try/except for user-friendly error messages; include raw git error in clone failure output
  • version.py: fix master version sort order (_master should be negative so master sorts last, not first)

Test

odev restore <db> <dump>.zip

Before: falls into degraded mode with IMMUTABLE error, then role "odoo" does not exist aborts the transaction.
After: restores cleanly in fast mode, proceeds directly to neutralization.

Jack41784090 and others added 2 commits June 18, 2026 11:43
- Wrap git clone/checkout in try/except for user-friendly error messages
- Include raw git error in clone failure message
- Fix master version sort order (should sort last, not first)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ng odoo role

Two bugs caused restoring SQL dumps to fail or fall into degraded mode:

1. `_buffered_sql_enable_extensions` used a `for...else` that only called
   `unaccent()` when the loop completed without `break`. Since the loop also
   breaks on the line-limit (100 lines), any real dump without an IMMUTABLE
   wrapper in its header would silently skip the unaccent pre-install, causing
   "functions in index expression must be marked IMMUTABLE" at restore time.
   Rewrote to an explicit `immutable_defined` flag.

2. Odoo dumps commonly end with `GRANT CREATE ON SCHEMA public TO odoo`.
   With `--single-transaction -v ON_ERROR_STOP=1` (fast mode), a missing
   `odoo` role aborted and rolled back the entire restore. Added `ensure_roles()`
   to pre-create the conventional `odoo` role before each SQL restore.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ikcha-odoo ikcha-odoo marked this pull request as draft June 18, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants