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] chunked: explicitly flush on every iteration #364

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

ivantodorovich
Copy link
Contributor

f"chunked method might not work as expected in Odoo {version_info[0]}. "
"Please report any issue you may find and consider bumping this warning "
"to the next version otherwise."
)
Copy link
Member

Choose a reason for hiding this comment

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

How does this relate to the rest of OpenUpgrade? Would we need a similar warning for every method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quoting @pedrobaeza here: #362 (comment)

Well, this is the only method where it mixes ORM. The rest is thought for handling database things, so I don't think the rest are affected.

I don't think I have enough knowledge of this tool to answer this.

I was just bitten by the fact that I tried to use this method in 16.0 and got corrupted data as a result because of this silent error 😓 My motivation is preventing other people from going through the same in future versions, in case something like this changes again.

if version_info[0] >= 16:

def reset():
records.env.invalidate_all(flush=True)
Copy link
Member

Choose a reason for hiding this comment

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

True is the default argument to flush. Would you consider leaving it out, as is conventional for defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is. I wanted to make it clear that flush is happening, which is something you may not immediately realize by just reading records.env.invalidate_all(). But I can remove it and let the default play out if you think it's best

else:
raise Exception("Not supported Odoo version for this method.")
size = core.models.PREFETCH_MAX
model = records._name
ids = records.with_context(prefetch_fields=False).ids
for i in range(0, len(ids), size):
invalidate()
reset()
Copy link
Member

Choose a reason for hiding this comment

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

I like having a name like invalidate as it reflects the aim more clearly and is aligned with the underlying Odoo methods it calls. Can you tell my why you changed 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.

My reasoning comes from the fact that we're not only invalidating the "read cache", we're also flushing the "to write cache"

Something like flush_and_invalidate seemed more accurate but it's long and explicit. Then I thought for each iteration a "reset" of the cache is done, hence the name.

In any case, I've extracted the invalidation/flushing to a separate method, as you suggested


elif version_info[0] >= 8:

def reset():
Copy link
Member

Choose a reason for hiding this comment

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

A version dependent shorthand method to invalidate the cache might proof to be useful outside of chunked. Would you consider moving it to openupgrade_tools.py? It might also be an aesthetic improvement, depending on your taste of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure ;) Check out the latests changes.

Copy link
Member

@StefanRijnhart StefanRijnhart 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 updates!
(code review, no test)

@pedrobaeza pedrobaeza merged commit 14245f3 into OCA:master Apr 11, 2024
2 checks passed
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.

3 participants