-
Notifications
You must be signed in to change notification settings - Fork 339
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
Create router map doesnt work well with properties #137
Comments
Hello. thanks for the report. I tried reproduce the problem as you described in a minimal example, but I failed. Can you show some code that show the problem? |
Sure , it should be sufficient to add to the basic example , in the ChargePoint class
@Property
def foo(self):
raise Exception(“this will be thrown when router is set up”)
But I need to unpatch my fixed version of the library to verify that. Will test tomorrow and get back with minimal example
… 19 okt. 2020 kl. 21:01 skrev Auke Willem Oosterhoff ***@***.***>:
Hello. thanks for the report. I tried reproduce the problem as you described in a minimal example, but I failed. Can you show some code that show the problem?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Here is a minimal unittest that will provoke the error and thus fail
|
Thanks for the code. I was able to reproduce the error. |
excellent, do you want me to do a PR for my solution? |
Sure! It would be great. |
just did it, all tests passed locally, CI is running right now |
For subclasses of `ChargePoint` using `@property` generating the route map could have unintended side effects. The function `ocpp.routing.create_route_map()` iterates over all attributes of the subclass, thus executing the method decorated with `@property`. This commit addressed that issue. Fixed: mobilityhouse#137 Co-authored-by: Auke Willem Oosterhoff <[email protected]>
If
you have a class containing properties the getters are called when the ocpp library is building its route map since it iterates att the attributes in the objectin router.py
The problem is with the getattr call, if this is a property it will then actually call the getter method, which in most cases is unwanted.
One solution that I have found is to have a global list in router.py that contains all the routables. The on and after decorators can then append the method name to this list. Then during the call to create router map instead of iterating the object attributes this list can be iterated
The text was updated successfully, but these errors were encountered: