-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactor sort_keys
implementation
#970
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.
The code itself looks good, I would like to see some more error handling and documentation on the decisions that were made so that it will be in the git history
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
@classmethod | ||
def set_sort_keys(cls, v: Any, info: ValidationInfo) -> Any: | ||
"""Set sort keys for all TableModels if present in FieldInfo.""" | ||
if isinstance(v, (TableModel,)): |
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.
Because of the nesting I would prefer some early returns here instead.
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 like the solution. Making use of the schema to set the information. I would love to eventually see this coming from the generated code instead.
Fixes #956
While ideally we set the sort_keys on the Schema of a TableModel, or on the TableModel themselves, this is not directly possible AFAIK:
The previous approach was to hold the sort keys in a
Dict[table, sort_keys]
on a NodeModel (which holds multiple tables), and passing them on when save/sort was called from the Node. This PR improves on that approach by introducing a private _sort_keys on the TableModel, which is always set (from an empty list by default) on initialization from the NodeModel.Instead of keeping a separate Dict with sort_keys on a NodeModel, we now set them in the
Field
attributejson_schema_extra
(the only customizable attribute of a Field) for each field. Each field of a NodeModel is now validated by default (also on assignment), and if a sort_keys is present for a fieldtype, it is set on the TableModel.Based on the initial exploration by @deltamarnix in https://github.com/Deltares/Ribasim/tree/feat/sort-keys-in-tablemodel