-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/sckan-273 #354
Conversation
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) |
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.
@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.
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 believe we could do:
```
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults_without_state)
connectivity_statement.refresh_from_db()
```
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.
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
.
Just to clarify a little bit the original problem. As you mentioned, if an existent statement had changes it would transition to exported. This is in theory non problematic because later there's a set of instructions responsible to move it to invalid. However the state of the statement was not refreshed and that's where the real problem lies. Here's an example of the problem: Statement A exists and is Invalid |
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 understand that the solution proposed is to not do the initial transition to Exported.
Let's see the possible scenarios:
- Statement A is in Exported and has no problems ✅
- Statement A is in Exported and has problems, then it's moved to Invalid by the transition check ✅
- Statement A is in Invalid and has problems, a new note is added, no transition is necessary ✅
- Statement A is in Invalid and has no problems. It should be moved to exported but currently I don't think it's. ❌
I think we need to add something, after the update without the state, on the lines of:
if connectivity_statement.state != CSState.EXPORTED:
# Use the FSM transition method
connectivity_statement.exported()
connectivity_statement.save()
```
@@ -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) |
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.
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)
@@ -634,7 +634,10 @@ def npo_approved(self, *args, **kwargs): | |||
|
|||
@transition( | |||
field=state, | |||
source=CSState.NPO_APPROVED, | |||
source=[ |
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.
NOTE: allow to export from invalid.
Jira ticket - SCKAN-273
About the issue - of statements getting converted from exported to invalid and vice versa.
Previously:
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults)
IMO - we should not update the default state here (since the default state is EXPORTED). So the problem we were facing - happened because if the statement had any changes, then - it was getting converted to EXPORTED.
This alone should fix the issue. Since now - it is not getting converted to EXPORTED, and hence would not be needing the conversion back to INVALID. However following is a
good to have
.i.e.
connectivity_statement = ConnectivityStatement.objects.filter(reference_uri=reference_uri).first()
instead of
since it doesn't get the latest for the state field. Which later caused errors (before the above fix) here.
Example of bad update before:
Once the statement was converted to EXPORTED state due to defaults, line still thinks it is in invalid state (and hence doesn't move it to INVALID - but will convert this very statement to INVALID the next time we run the script). However, we did update and fetched the latest the before.