-
Notifications
You must be signed in to change notification settings - Fork 20
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
Proof of Concept: Dynamically Generated DataModels #221
Proof of Concept: Dynamically Generated DataModels #221
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #221 +/- ##
==========================================
+ Coverage 96.74% 96.88% +0.14%
==========================================
Files 29 31 +2
Lines 2398 2379 -19
==========================================
- Hits 2320 2305 -15
+ Misses 78 74 -4
☔ View full report in Codecov by Sentry. |
A DataModel object class | ||
""" | ||
if hasattr(_mixins, mixin := f"{datamodel_name}Mixin"): | ||
class_type = (DataModel, getattr(_mixins, mixin)) |
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.
There is a bug here, things like the
get_primary_array_name
cannot be properly overridden as desired.
This is because the "order" of inheritance in Python is right to left meaning it applies the right most class structure first then proceeds to the left. Thus for the get_primary_array_name
example the Mixin will load its version and then it will be overloaded by the DataModel object. This is the reverse of what we want.
This should not effect anything added by the Mixin (as one would normally do), but since this is the way I am dynamically injecting alterations to dynamically created objects, we need to pay attention to this ordering.
88518bc
to
492c1a5
Compare
cadbc20
to
9c8ba9a
Compare
9c8ba9a
to
19ebd6c
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.
Looks good to me and pretty straightforward, aside from the needed changes to a couple docstrings.
|
||
def get_primary_array_name(self): | ||
""" | ||
Returns the name "primary" array for this model, which |
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.
This should be changed to reflect that it is the override, rather than intended to be overridden.
|
||
def get_primary_array_name(self): | ||
""" | ||
Returns the name "primary" array for this model, which |
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.
Likewise.
124d00f
to
af4e8d9
Compare
get_primary_array_name is currently not functional, these tests will detect when it starts functioning
af4e8d9
to
5ca92e1
Compare
After the roman tag-up this week (22 June 2023), I was left wondering how difficult would it be to dynamically generate the datamodels from RAD now that the
datamodel_name
meta data has been added to the schemas.As it turns out, this is not that difficult if one builds on the proposed changes in PRs #213 and #214 (This PR is based off a a rebase of #214 onto #213). This PR move the datamodels from being statically defined in code to dynamic code generation as discussed.
Checklist
CHANGES.rst
under the corresponding subsection