-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[ADD] api_foreach: Provide api.one replacement #615
Conversation
* Create api method to match operation of api.one, call it foreach
63c1053
to
5e4f7bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious on how this works without ugly import statements. Does it work with the 'from odoo import api'?
It doesn't, and that's part of the reason why this is a WIP & not actually unit tested yet. I'm now working out how to monkey patch it into another namespace using |
358dd34
to
a3a733f
Compare
a3a733f
to
be8a96a
Compare
Well that was fairly easy, was just a matter of an attribute set in a post_load. It works too, which is always a plus 😄
|
Alright, ready for review. I'll squash my disastrous commit history after 😉 |
Great! Now you need to make sure this module is loaded first. I'm not sure if a sequence value in the manifest can go that. |
Wouldn't any module using |
👍 nice |
@lasley good idea. Nevertheless why do you try to monkey patch odoo and provides this nice functionality as an addon? IMO the right way to propose this functionality is to put it in a true python module. Addons using this decorator should only add the module in the python external dependencies. |
@lmignon you mean an OCA repo for a Python |
@lmignon sorry: an OCA repo for a Python package to extend the core? Sounds good to me. |
@dreispt I mean that this one should be packaged as a python package and therfore have its own repo... |
I use some Odoo helper methods, so this would need to be rewritten to be standalone. It wouldn't be incredibly difficult though and this could be used outside of Odoo context, as shown in my test. The |
@lasley your python lib must depend of odoo. Therefore you can use all the methods provided by odoo |
Ah that makes sense and would guarantee our load order. We would lose the ability to import through the pre-existing namespace though, so another explicit import would need to be added to each file before it could be used:
vs
The first will allow for a repo to simply be awk'd for |
@lasley odoo.api is not a namespace package. Therefore it's not allowed to extend it. I prefer an explicit import in place of a monkey patch. I don't see this additional import as a something negative. If we decide to declare this new decorator in a new namespace package named oca.api I see this new import as a good opportunity to promote oca since the name will be explicitly used into the code. . |
I like odoo addon module. @lmignon |
@moylop260 the purpose of this module is to extend the odoo api. |
@lmignon - I agree that it is good Python practice to make a lib, however doing so will rule out the use of this functionality on Odoo SaaS (and my own) due to the user needing to install additional Python depends. This is reason enough to break good practice IMO |
I prefer this also as an Odoo module, as you have a common way of using this functionality. It has already been done in other libraries like https://github.com/OCA/server-tools/tree/8.0/datetime_formatter |
The datetime_formatter is an odoo addon since it extend an odoo model... |
What about have 2 options a odoo addon and a python library? |
The functionality is nice and I'll not block this PR even if I disagree on the way it's provided. I'm just disappointed and frustrated to see that it's so difficult to evolve to more python standards... |
I'm not opposed to making the change. My question is how we allow SaaS customers to use this functionality if packaged as Python lib? |
@lasley the same apply to all the addons that require an additional python library. We have lots of them in OCA. |
@lasley a good compromise could be to avoid the patch on the |
I agree with @lmignon, this monkey-patching is not good. It can lead to weird situations, where your addon lacks the dependency but works because another database is present that installed it (you are polluting the whole odoo namespace in a multidatabase setup). In fact I already thought about this before, but fell into the same conclusion before even writing anything: this should be a lib. I think the good place for this would be a new repo called "OCA/ocalib" or something like that, and make it pip-installable, and release-tagged. Then you'd simply add it to external dependencies and in your code:
Also, I would not create this And, given the problem is that
There are lots of possible ideas that would be great for that lib repo. Some of them:
Helpers, helpers, helpers... Well, just some quick ideas, I think having such playground would be quite beneficial. Probably many of you have had some need in the past that could easily have become part of a library. So, for myself, 👍 for the idea (with some improvements), but 👎 for setting it as an addon. |
@yajo If we go with a new lib it would be nice to start with a namespace package' 'oca'. We could start with 'oca.api' where we could add code that leverage/extend the odoo.api (foreach). We can also imagine an other lib 'oca.test' etc.. |
Bah I don't like the fact that SaaS can't be supported, but I can just install it on my SaaS so it is. @yajo raises the concern of the multi-database, which is correct and a blocker IMO. The long namespace of an addon without the monkey patch would work, but is too long for how often it would be typed. In light of these arguments, I agree with @lmignon about the
My position on this is that it is confirmed as deprecated, so we can no longer use it in upgraded code. I block for usage of I require this functionality for a rather large project in order to fix a bunch of singleton issues without creating a diff-tastrophy by adding a bunch of record loops, resorting to moving everything to private methods that are looped, or limiting functionality with
Hmmm this would also allow for some interesting techniques allowing for the returning id/val dicts too. Or really whatever. I like.
To clarify if we have an |
👍
Yes, that's the idea. I guess if you pass Indeed this For instance, another problem it could solve is to check versions of python dependencies. Or it could skip chunks of code in an addon depending on Odoo's version. It would be nice if we could even get to have 1 single branch for all Odoo versions and programatically setting the |
Yeah I'm not sure how we'd version effectively if we didn't have just one branch. I do think that we'll need to come to a determination of which Odoo versions are explicitly supported though. My vote is on the latest three versions, same as Odoo SA release schedule. Works out well for us this cycle too, because no old API. The alternative could maybe be an introspection layer to validate Odoo versions before allowing use of certain features. This seems fairly exponential in terms of logic weight though.
Might be best - I'm thinking of a lot of edge cases that could crop up with this, particularly with the |
This has moved to LasLabs/python-oca#1 - please feel free to review it. I'll create an email to petition moving the repo into OCA sometime soon. If that's something we should do now instead, just let me know! |
Syncing from upstream OCA/server-tools (12.0)
I grudgingly present
api.foreach
as outlined by @dreispt in odoo/odoo#13199 (comment)Still need to add tests & make the import not dirty, just wanted to let everyone know there is a light at the end of the tunnel 😉