Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] load_data: update to version 17.0 #369

Merged
merged 1 commit into from
May 15, 2024

Conversation

royle-vietnam
Copy link
Contributor

changed on 17.0
(odoo/odoo@5bf1207)

@pedrobaeza
Copy link
Member

Thanks for this change. I'm wondering if we should instead convert the first argument to env_or_cr and delegate the responsibility of passing env or cr to the migration scripts, documenting it in the method that for 17+, the env is needed.

What do you think, @StefanRijnhart @legalsylvain @hbrunn ?

@legalsylvain
Copy link
Contributor

I dont get it.

@pedrobaeza
Copy link
Member

On v16-, you call the method load_data(cr, ...). On v17+, you call it load_data(env, ...).

@legalsylvain
Copy link
Contributor

OK !

You propose to replace

def load_data(cr, module_name, filename, idref=None, mode="init"):

by

def load_data(env_or_cr, module_name, filename, idref=None, mode="init"):

Adding a comment to say that an cr is required until 16 and an env is required since 17, right ?

Personnaly, I prefer to keep the same signature def load_data(cr, module_name, filename, idref=None, mode="init"):

Then, add :

env_or_cr = api.Environment(cr, SUPERUSER_ID, {}) if version_info[0] >= 17 else cr

then simply replace tools.convert_xml_import(cr, module_name, fp, idref, mode=mode)
by tools.convert_xml_import(env_or_cr, module_name, fp, idref, mode=mode)

But both works, so it's maybe a matter of taste. I think that it can maybe generate more errors to change the type of the argument, depending of the version of the module that call the function.

@royle-vietnam
Copy link
Contributor Author

OK !

You propose to replace

def load_data(cr, module_name, filename, idref=None, mode="init"):

by

def load_data(env_or_cr, module_name, filename, idref=None, mode="init"):

Adding a comment to say that an cr is required until 16 and an env is required since 17, right ?

Personnaly, I prefer to keep the same signature def load_data(cr, module_name, filename, idref=None, mode="init"):

Then, add :

env_or_cr = api.Environment(cr, SUPERUSER_ID, {}) if version_info[0] >= 17 else cr

then simply replace tools.convert_xml_import(cr, module_name, fp, idref, mode=mode) by tools.convert_xml_import(env_or_cr, module_name, fp, idref, mode=mode)

But both works, so it's maybe a matter of taste. I think that it can maybe generate more errors to change the type of the argument, depending of the version of the module that call the function.

OK !

You propose to replace

def load_data(cr, module_name, filename, idref=None, mode="init"):

by

def load_data(env_or_cr, module_name, filename, idref=None, mode="init"):

Adding a comment to say that an cr is required until 16 and an env is required since 17, right ?

Personnaly, I prefer to keep the same signature def load_data(cr, module_name, filename, idref=None, mode="init"):

Then, add :

env_or_cr = api.Environment(cr, SUPERUSER_ID, {}) if version_info[0] >= 17 else cr

then simply replace tools.convert_xml_import(cr, module_name, fp, idref, mode=mode) by tools.convert_xml_import(env_or_cr, module_name, fp, idref, mode=mode)

But both works, so it's maybe a matter of taste. I think that it can maybe generate more errors to change the type of the argument, depending of the version of the module that call the function.

@legalsylvain Thank you for your solution. I find it very interesting and low risk. I have fixed it according to your solution.

@pedrobaeza
Copy link
Member

Why I was talking to pass env is for the same reason as stated in the Odoo commit: to re-use the environment and avoid to regenerate it each time, and to share the context. Don't you think it's worth?

@royle-vietnam
Copy link
Contributor Author

Why I was talking to pass env is for the same reason as stated in the Odoo commit: to re-use the environment and avoid to regenerate it each time, and to share the context. Don't you think it's worth?

@pedrobaeza I have updated it according to your suggestion, please review it

@@ -329,21 +337,21 @@ def load_data(cr, module_name, filename, idref=None, mode="init"):
if ext == ".csv":
noupdate = True
tools.convert_csv_import(
cr, module_name, pathname, fp.read(), idref, mode, noupdate
env_or_cr, module_name, pathname, fp.read(), idref, mode, noupdate
)
elif ext == ".yml":
yaml_import(cr, module_name, fp, None, idref=idref, mode=mode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one hasn't been changed, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaml_import was removed from Odoo after 11 anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but right now, the code will fail in 11-, as cr has no value for that case. Assign previously cr = env_or_cr, or directly put here env_or_cr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I added more at line 310

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patience attending our comments.

@pedrobaeza pedrobaeza merged commit dfad8f2 into OCA:master May 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants