Skip to content
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

Feature/sckan-273 #354

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def create_or_update_connectivity_statement(statement: Dict, sentence: Sentence,
reference_uri=reference_uri,
defaults=defaults
)
if not created:
if not created:
if has_changes(connectivity_statement, statement, defaults):
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults)
fields_to_refresh = [field for field in defaults.keys() if field != 'state']
connectivity_statement.refresh_from_db(fields=fields_to_refresh)
defaults_without_state = {field: value for field, value in defaults.items() if field != 'state'}
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults_without_state)
Copy link
Contributor Author

@D-GopalKrishna D-GopalKrishna Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afonsobspinto - keeping the filter instead of the get here - since we cannot update a get (can only update a queryset)
AttributeError: 'ConnectivityStatement' object has no attribute 'update'

also doing connectivity_statement = ConnectivityStatement.objects.filter(reference_uri=reference_uri).first() since, we get

ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults_without_state)
>>> 1

as return value after the update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we could do:

        ```
        ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults_without_state)
        connectivity_statement.refresh_from_db()
        ```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the following?

fields_to_refresh = [field for field in defaults.keys() if field != 'state']
connectivity_statement.refresh_from_db(fields=fields_to_refresh)

since the connectivity_statement.refresh_from_db() would lead to AttributeError: Direct state modification is not allowed.

connectivity_statement = ConnectivityStatement.objects.filter(reference_uri=reference_uri).first()
add_ingestion_system_note(connectivity_statement)

validation_errors = statement.get(VALIDATION_ERRORS, ValidationErrors())
Expand Down