-
Notifications
You must be signed in to change notification settings - Fork 9
Fix multiple compounds update #65
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
Conversation
Added entries for files generated by tests to .gitignore to prevent them from being tracked in version control.
Replaced instance-level access to model_fields with class-level access (self.__class__.model_fields) throughout DataverseBase. This ensures correct field resolution, especially when model_fields is defined at the class level.
The add function now marks the attribute as changed and updates the _changed set of the created subclass object with the provided keyword arguments. Also, _changed is excluded from the generated function signature to prevent unintended parameter exposure.
Introduces a new integration test to verify updating a dataset with multiple fields, including authors, description, contact, and other IDs. Also updates unit tests to include PrivateAttr _changed in test models for change tracking.
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.
Pull Request Overview
This pull request fixes an issue where dataset updates fail after adding compound objects using dedicated add_xyz methods. The fix ensures that the updater's change tracking mechanism properly recognizes these additions by updating the _changed set for both parent and child objects.
- Modified the add-function template to mark attributes as changed when objects are added
- Updated model field references to use class-level attributes for consistency
- Added comprehensive integration tests to verify the fix works correctly
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| easyDataverse/classgen.py | Updated add function generation to track changes and skip _changed in signatures |
| easyDataverse/base.py | Changed model field references to use class-level attributes consistently |
| tests/unit/test_connect.py | Added _changed attribute to test models and updated imports |
| tests/integration/test_dataset_update.py | Added integration test for multiple field updates including compound objects |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Thank you very much for the quick resolution! Tested it and the .update() works now (after removing and re-installing the package. Maybe bump the version number a little?). |
Updated the project version from 0.4.4 to 0.4.5 to prepare for a new release.
|
@JulianRein thanks for the quick feedback and the reminder! Bumped the version and will merge the PR now |
This pull request addresses an issue raised in #64, where adding compound objects to a class and subsequently updating the dataset fails because the updater is not informed about the changes. This occurs because the updater checks the
_changedset to determine if an attribute or collection has changed and should be included in the dataset update. However, when using dedicatedadd_xyzmethods, these fields remain unchanged, leading the updater to assume they should not be updated.To resolve this issue, the add-function template has been modified to extend the
_changedfield in both the parent and to-be-added child objects. Additionally, the test suite has been updated to ensure that the system behaves as expected in these scenarios.Model change tracking and consistency:
model_fieldsinDataverseBasemethods to use the class-level attribute (self.__class__.model_fields), ensuring consistent behavior when dealing with inherited fields. [1] [2] [3] [4]Dynamic function generation and change tracking:
generate_add_functionineasyDataverse/classgen.pyso that added objects are properly tracked as changed, and their own changed fields are updated when created.create_function_signatureto skip the_changedattribute when generating function signatures, preventing unintended exposure of internal attributes.Testing and coverage improvements:
test_dataset_update_with_multiple_fieldsto verify that multiple fields, including nested and compound fields, are correctly updated and persisted in datasets._changedattribute in test model classes and their annotations, ensuring that change tracking works as expected during testing. [1] [2]SetandPrivateAttrin unit tests to support the new change tracking mechanism.Issues to be resolved