-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fix import element sorting when saving (for related items) #1078
Conversation
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
I broke the sorting with typo, it should be Line 451 in ea118ed
|
…to legacy Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
…fle to elements Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
rdmo/core/xml.py
Outdated
@@ -257,6 +257,21 @@ def validate_pre_conversion_for_missing_key_in_legacy_elements(elements, version | |||
raise ValueError(f"Missing legacy elements, elements containing 'key' were expected for this XML with version {version} and elements {models_in_elements}.") # noqa: E501 | |||
|
|||
|
|||
def update_related_elements(elements: Dict, related_uri: str, related_model: str, related_key: str, field_name: str): |
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.
What ist this method used for?
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 think there was something broken/missing with the current legacy xml parsing because the related elements are not written back into the ascending elements (following the current element Models).
For example, for the sections I added:
del element['catalog'] # sections do not have catalog anymore
This is correct right? They don't have catalog
anymore..
But then the corresponding catalog needs to know about this section so I've added this function to "update" the catalog in that case.
The same then holds for pages
, questionsets
, questions
etc.. right?
Still it's for the legacy xml's.. I could also revert if needed...
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.
- rename
DEFAULT_XML_VERSION
toLEGACY_XML_VERSION
… cases Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
Signed-off-by: David Wallace <[email protected]>
…zation Signed-off-by: David Wallace <[email protected]>
rdmo/management/import_utils.py
Outdated
try: | ||
# Instantiate the DRF field and use it to validate and convert the value | ||
drf_field = drf_field_class() | ||
element[field_name] = drf_field.to_internal_value(element_field_value) |
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.
Ive added some deserialization via the DRF Fields in here, it happens only for the so-called 'extra fields' of a rdmo model.
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.
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 am arguing about creating to many functions all the time, but this thing could be a relatively generic function validate_with_serializer_field(instance, field_name)
or something.
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.
yes that's true, I can refactor it to that, as the last change of this PR
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.
... as the last change of this PR
🙄
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.
ok, Ive refactored it into a separate function, it could be moved to core
it it's needed by other apps/functions..
rdmo/management/import_utils.py
Outdated
try: | ||
# Instantiate the DRF field and use it to validate and convert the value | ||
drf_field = drf_field_class() | ||
element[field_name] = drf_field.to_internal_value(element_field_value) |
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.
rdmo/management/import_utils.py
Outdated
try: | ||
# Instantiate the DRF field and use it to validate and convert the value | ||
drf_field = drf_field_class() | ||
element[field_name] = drf_field.to_internal_value(element_field_value) |
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 am arguing about creating to many functions all the time, but this thing could be a relatively generic function validate_with_serializer_field(instance, field_name)
or something.
Signed-off-by: David Wallace <[email protected]>
thanks for the review! |
Description
Fixes for the Import Feature
dev-2.2.0
)append_element
order
through field items toint
element
that are not relevant for the import (like legacy keys)extra_fields
) is done by theinstance.full_clean()
and these instance values are written back into theelement[field]
float
forFloatField
otherwise astr
will be compare tofloat
Motivation and Context
Made an overview of the models and the relations with the CLI tool
graph_models
How has this been tested?
Screenshots (if appropriate)
Types of Changes
Checklist