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

TP2000-143: 500 on Measure Detail view #497

Merged
merged 6 commits into from
Feb 18, 2022

Conversation

gabelton
Copy link
Contributor

@gabelton gabelton commented Feb 17, 2022

Why

It shouldn't be possible to create a measure with the same sid as another measure from a different version_group. There's still a separate issue being explored in this ticket ( https://uktrade.atlassian.net/browse/TP2000-42 ) around synchronising measure sids so that data engineers can make changes alongside those of Tariff Managers on the frontend, but this should add a bit of extra security in the meantime.

What

Copy link
Contributor

@simonwo simonwo left a comment

Choose a reason for hiding this comment

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

Is it possible to do this in a general way and apply it anywhere else we have a SID? Also, are there any implications for this being a validation and not a business rule e.g. will it be possible to import duplicate SIDs and fix them later, or will this prevent that?

@gabelton
Copy link
Contributor Author

I think a 500 error would block import, so maybe a business rule is better. Might make generalising it for other components a bit easier too

@gabelton
Copy link
Contributor Author

I added a test for measures just because that was what originally motivated the PR, but I think tests in common/tests/test_business_rules should already have us covered.

@gabelton
Copy link
Contributor Author

This is affecting github actions: aws/aws-sam-cli#3661

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2022

Codecov Report

Merging #497 (85ed1c9) into master (d3b9254) will increase coverage by 0.01%.
The diff coverage is 99.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
+ Coverage   91.99%   92.00%   +0.01%     
==========================================
  Files         294      295       +1     
  Lines       18151    18224      +73     
  Branches     1450     1453       +3     
==========================================
+ Hits        16698    16767      +69     
- Misses       1186     1189       +3     
- Partials      267      268       +1     
Impacted Files Coverage Δ
conftest.py 95.21% <ø> (ø)
workbaskets/admin.py 90.90% <83.33%> (-1.69%) ⬇️
additional_codes/models.py 95.45% <100.00%> (+0.06%) ⬆️
commodities/models/orm.py 91.20% <100.00%> (+0.04%) ⬆️
common/models/mixins/description.py 85.71% <100.00%> (+0.20%) ⬆️
common/tests/test_models.py 98.96% <100.00%> (ø)
footnotes/tests/test_views.py 100.00% <100.00%> (ø)
geo_areas/models.py 95.12% <100.00%> (+0.06%) ⬆️
measures/models.py 95.94% <100.00%> (+0.01%) ⬆️
measures/tests/test_business_rules.py 96.89% <100.00%> (+0.01%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b57916...85ed1c9. Read the comment docs.

measures/models.py Outdated Show resolved Hide resolved
measures/models.py Outdated Show resolved Hide resolved
Copy link
Contributor

@simonwo simonwo left a comment

Choose a reason for hiding this comment

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

There are a few other models that already have rules that cover uniqueness… can you double check we're not doubling up?

@@ -176,6 +177,7 @@ def footnote_application_codes(self) -> Set[ApplicationCode]:
business_rules.NIG31,
business_rules.NIG34,
business_rules.NIG35,
UniqueIdentifyingFields,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I think in this case NIG1 actually has a slightly different requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, so they're allowed to have the same sid, as long as their validity periods don't overlap

@gabelton gabelton merged commit 8dd8ab2 into master Feb 18, 2022
@gabelton gabelton deleted the TP2000-143-500-on-Measure-Detail-view branch February 18, 2022 17:29
kintisheff pushed a commit that referenced this pull request Feb 21, 2022
* add custom sid validation in Measure.clean and call full_clean in Measure.save

* add vanilla UniqueIdentifyingFields business rule to models with sid as only identifying field

* specify markupsafe version

* remove uniqueidentifyingfields where rule already exists
kintisheff pushed a commit that referenced this pull request Mar 8, 2022
* add custom sid validation in Measure.clean and call full_clean in Measure.save

* add vanilla UniqueIdentifyingFields business rule to models with sid as only identifying field

* specify markupsafe version

* remove uniqueidentifyingfields where rule already exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants