[FIX] local: fix SQL restore - unaccent IMMUTABLE detection and missing odoo role#169
Draft
ikcha-odoo wants to merge 2 commits into
Draft
[FIX] local: fix SQL restore - unaccent IMMUTABLE detection and missing odoo role#169ikcha-odoo wants to merge 2 commits into
ikcha-odoo wants to merge 2 commits into
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Restoring SQL dumps (e.g.
odev restore <db> <file>.zip) consistently failed with:Two bugs caused this, and fixing the first exposed the second.
Fix 1 —
_buffered_sql_enable_extensions: brokenfor...elselogicodev pre-installs an IMMUTABLE
public.unaccent(text)wrapper before restoring when the dump doesn't already define one (PostgreSQL's built-inunaccentisSTABLE, which is rejected in index expressions).The detection used a
for...elsethat only calledunaccent()when the loop completed withoutbreak. 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 limitbreakandunaccent()was silently skipped.Fix: explicit
immutable_definedflag;unaccent()is called whenever the marker isn't found within the scanned header.Fix 2 —
ensure_roles(): missingodoorole aborts fast-mode restoreOnce fix 1 kept the restore in fast mode (
--single-transaction -v ON_ERROR_STOP=1), a new error surfaced: Odoo dumps commonly end withGRANT CREATE ON SCHEMA public TO odoo. WithON_ERROR_STOP=1, a missing localodoorole 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 onunaccent()) that pre-creates the conventionalodoorole 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 outputversion.py: fix master version sort order (_mastershould be negative so master sorts last, not first)Test
Before: falls into degraded mode with IMMUTABLE error, then
role "odoo" does not existaborts the transaction.After: restores cleanly in fast mode, proceeds directly to neutralization.