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
Show file tree
Hide file tree
Changes from 4 commits
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
5 changes: 4 additions & 1 deletion backend/composer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ def npo_approved(self, *args, **kwargs):

@transition(
field=state,
source=CSState.NPO_APPROVED,
source=[
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: allow to export from invalid.

CSState.NPO_APPROVED,
CSState.INVALID
],
target=CSState.EXPORTED,
conditions=[ConnectivityStatementStateService.is_valid],
permission=ConnectivityStatementStateService.has_permission_to_transition_to_exported,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ def create_invalid_note(connectivity_statement: ConnectivityStatement, note: str
type=NoteType.ALERT,
note=f"Invalidated due to the following reason(s): {note}"
)


def do_transition_to_exported(connectivity_statement: ConnectivityStatement):
system_user = User.objects.get(username="system")
connectivity_statement.exported(by=system_user)
connectivity_statement.save()
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from composer.services.cs_ingestion.helpers.getters import get_sex, get_circuit_type, get_functional_circuit_role, \
get_phenotype, get_projection_phenotype
from composer.services.cs_ingestion.helpers.notes_helper import do_transition_to_invalid_with_note, create_invalid_note, \
add_ingestion_system_note
add_ingestion_system_note, do_transition_to_exported
from composer.services.cs_ingestion.models import ValidationErrors


Expand All @@ -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 All @@ -50,6 +50,9 @@ def create_or_update_connectivity_statement(statement: Dict, sentence: Sentence,
do_transition_to_invalid_with_note(connectivity_statement, error_message)
else:
create_invalid_note(connectivity_statement, error_message)
else:
if connectivity_statement.state != CSState.EXPORTED:
do_transition_to_exported(connectivity_statement)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move to EXPORTED state (default) if not in EXPORTED state - if there's no validation errors.

Reason to include this: (credit thanks - @afonsobspinto : ) )

If a statement was in INVALID state in the past; but if it has no validation errors when running it again in the future, then it should to be moved to EXPORTED state.

To cover the fourth edge case here - #354 (review)


update_many_to_many_fields(connectivity_statement, statement, update_anatomical_entities)
statement[STATE] = connectivity_statement.state
Expand Down