Skip to content

Commit

Permalink
fix(backup): convert odoo regex extensions
Browse files Browse the repository at this point in the history
The backup image [accepts a regexp on `DBS_TO_INCLUDE`][1]. But [Odoo uses a regexp with custom extensions][2] (`%h` and `%d`).

If you use any of those extensions, the backup jobrunner will fail with `CalledProcessError`.

Additionally, regexps usually contain a `$` symbol, which [needs to be escaped for docker-compose][3].

[1]: https://github.com/Tecnativa/docker-duplicity#dbs_to_includeexclude
[2]: https://www.odoo.com/documentation/16.0/developer/reference/cli.html#cmdoption-odoo-bin-db-filter
[3]: https://docs.docker.com/compose/compose-file/compose-file-v2/#variable-substitution

BREAKING CHANGE: if your dbfilter contained `$$` previously, to do that escaping yourself, you will have to convert it to a single `$`

@moduon MT-4191
  • Loading branch information
yajo committed Jul 9, 2024
1 parent 964b624 commit 4a21f81
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:
init: true
environment:
DB_VERSION: "{{ postgres_version or 'latest' }}"
DBS_TO_INCLUDE: "{{ odoo_dbfilter }}"
DBS_TO_INCLUDE: "{{ odoo_dbfilter | replace('$', '$$') | replace('%d', '.*') | replace('%h', '.*') }}"
DST: "{{ backup_dst }}"
{%- if smtp_relay_host %}
EMAIL_FROM: "{{ backup_email_from }}"
Expand Down
2 changes: 1 addition & 1 deletion prod.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- .docker/odoo.env
- .docker/db-access.env
environment:
DB_FILTER: "{{ odoo_dbfilter }}"
DB_FILTER: "{{ odoo_dbfilter | replace('$', '$$') }}"
DOODBA_ENVIRONMENT: "${DOODBA_ENVIRONMENT-prod}"
INITIAL_LANG: "{{ odoo_initial_lang }}"
{%- if smtp_relay_host %}
Expand Down
24 changes: 24 additions & 0 deletions tests/test_settings_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,27 @@ def test_dbfilter_default(
assert "DB_FILTER" not in test.services["odoo"].environment
assert prod.services["odoo"].environment["DB_FILTER"] == "^prod"
assert prod.services["backup"].environment["DBS_TO_INCLUDE"] == "^prod"


def test_dbfilter_custom_odoo_extensions(
cloned_template: Path, supported_odoo_version: float, tmp_path: Path
):
"""Fixes custom Odoo regexp extensions in dbfilter for the backup service."""
with local.cwd(tmp_path):
run_copy(
src_path=str(cloned_template),
dst_path=".",
data={
"odoo_version": supported_odoo_version,
"postgres_version": DBVER_PER_ODOO[supported_odoo_version]["latest"],
"backup_dst": "file:///here",
"odoo_dbfilter": "^%d_%h$",
},
vcs_ref="test",
defaults=True,
overwrite=True,
unsafe=True,
)
prod = DockerClient(compose_files=["prod.yaml"]).compose.config()
assert prod.services["odoo"].environment["DB_FILTER"] == "^%d_%h$$"
assert prod.services["backup"].environment["DBS_TO_INCLUDE"] == "^.*_.*$$"

0 comments on commit 4a21f81

Please sign in to comment.