-
Notifications
You must be signed in to change notification settings - Fork 191
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
Prevent nodes without registered entry points from being stored #3886
Prevent nodes without registered entry points from being stored #3886
Conversation
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.
Nice, thanks! Probably @giovannipizzi should give it a quick look also, to make sure he's on board with the new behavior.
f23d47c
to
e7bc9f8
Compare
Up until now it was possible to store instances of `Node` subclasses that do not have a registered entry point. Imagine for example the definition of a `Data` subclass called `SubClass` in a shell and an instance being stored. The node type string will be: `__main__.SubClass.` When trying to load this node at a later point in time, the type string can of course not be resolved to an importable class and the loader would raise an exception. The first change is that this exception is now turned into a warning and the loader falls back onto the `Data` class. Note that we do not use the `Node` class for this as this base class is also not storable and so the ORM logic is potentially ill-defined for instances of the base `Node`. Secondly, we now add a check to `Node.store` to make sure that the class corresponds to a registered entry point. If this is not the case, the store method will raise `StoringNotAllowed`. One unit test was deleted because its implementation was incorrect and was not actually testing what it was intending to test. Besides intended functionality is now covered by other tests.
e7bc9f8
to
bc95ffb
Compare
Codecov Report
@@ Coverage Diff @@
## develop #3886 +/- ##
===========================================
- Coverage 77.18% 77.18% -0.01%
===========================================
Files 457 457
Lines 33778 33795 +17
===========================================
+ Hits 26072 26084 +12
- Misses 7706 7711 +5
Continue to review full report at Codecov.
|
I have performed the following performance test on the branch of this PR and
I feel this is acceptable. @giovannipizzi and @greschd this is ready for review |
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 though a bit more about how this impacts developing Data
sub-classes. My conclusion is that this change is fine in that context, but I'll reproduce my thoughts here to see if you agree:
When developing the Data
nodes, one might want to work in an interactive context (REPL, Jupyter). The type strings in this case will be invalid, which makes storing impossible. However, even previously these stored nodes could not be loaded back, making the storing pointless. Interactive development of the Data
sub-classes can still happen on unstored nodes.
If the store / load cycle is really required in this context, one could add an escape hatch (validate_type_string
flag) to the store
method. But, in order to be useful, it would also require a way to load it back (like a MyDataClass.load_node(pk)
). I don't think either is really necessary.
Fixes #3457
Up until now it was possible to store instances of
Node
subclassesthat do not have a registered entry point. Imagine for example the
definition of a
Data
subclass calledSubClass
in a shell and aninstance being stored. The node type string will be:
__main__.SubClass.
When trying to load this node at a later point in time, the type string
can of course not be resolved to an importable class and the loader
would raise an exception.
The first change is that this exception is now turned into a warning and
the loader falls back onto the
Data
class. Note that we do not use theNode
class for this as this base class is also not storable and so theORM logic is potentially ill-defined for instances of the base
Node
.Secondly, we now add a check to
Node.store
to make sure that the classcorresponds to a registered entry point. If this is not the case, the
store method will raise
StoringNotAllowed
.One unit test was deleted because its implementation was incorrect and
was not actually testing what it was intending to test. Besides intended
functionality is now covered by other tests.