Repository navigation
Python refactor: Load object from ID using new convention - #6184
Conversation
|
In draft only because of pending dependent merge. There's only one commit to review, which can be filtered in the files view. |
There was a problem hiding this comment.
(not blocker, just thinking out loud about general issues) Do we need to ban custom objects that end in ID? If someone did that in a module today and then wrote a python module that depended on it would it break anything here in particular (besides the breakage server-side, which may make this moot)
There was a problem hiding this comment.
No, it's not an issue here for two reasons. 🙂
First, this is matching only scalars that end in ID and modules today don't create scalars.
Secondly, this is only used in the HasID Protocol below and the runtime checking on protocols is pretty basic, it only checks for the existence of the attribute (in this case it should be checking if the object has an id method), it doesn't check the types.
So there isn't much value in IDScalar here, just static type checking and documentation or just putting it down for later use as the Is[] part isn't standard, it's part of the beartype library and I wanted to remember that it supports matching anything with a lambda like this.
There was a problem hiding this comment.
To be thorough, even if we allow a user to create custom scalars in the near future I don't think they will be able to create a method called id, which would have to return a custom scalar ending in ID. But even if they could, the worst that could happen would be:
- On serialization that
idmethod would be called before sending the result to the server; - On deserialization it would call
loadXFromIDto return the object, which is added by the server automatically on id-able objects;
Even then there's a chance that the local machinery from object_type will kick in for the above before trying to use id. Not sure, would have to test for that order but it's something that can be controlled if needed.
Follow-up to dagger#5881, this is a refactor to simplify converting an ID scalar to object based on the new convention. Signed-off-by: Helder Correia <[email protected]>
70654ec to
0ecf003
Compare
Follow-up to #5881
This is a refactor to simplify converting an ID scalar to object based on the new convention.