[IMP] core: enforce format of module versions

As module versions can be single digit, an upgrade script for version
`x.y.z`, is currently parsed as an upgrade script for module
version `z` in Odoo `x.y`.
However 3-digits module versions are more common than single-digit ones
and developers may expect the `x.y.x` upgrade scripts to be major-less
scripts.
This ambiguity can lift off if we accept module versions to be **only**
2-digits or 3-digits. This however make the `x.y.z` upgrade script
major-less. This can be fixed by renaming the script to `x.y.z.0`.

Part-of: odoo/odoo#118420
This commit is contained in:
Christophe Simonis
2023-05-02 18:06:44 +02:00
parent 56d87dc792
commit 653ec8cf60
+12 -1
View File
@@ -331,7 +331,10 @@ def load_manifest(module, mod_path=None):
elif manifest['auto_install']:
manifest['auto_install'] = set(manifest['depends'])
manifest['version'] = adapt_version(manifest['version'])
try:
manifest['version'] = adapt_version(manifest['version'])
except ValueError as e:
raise ValueError(f"Module {module}: invalid manifest") from e
manifest['addons_path'] = normpath(opj(mod_path, os.pardir))
return manifest
@@ -426,7 +429,15 @@ def get_modules_with_version():
def adapt_version(version):
serie = release.major_version
if version == serie or not version.startswith(serie + '.'):
base_version = version
version = '%s.%s' % (serie, version)
else:
base_version = version[len(serie) + 1:]
if not re.match(r"^[0-9]+\.[0-9]+(?:\.[0-9]+)?$", base_version):
raise ValueError(f"Invalid version {base_version!r}. Modules should have a version in format `x.y` or `x.y.z`.")
return version
current_test = None