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

Fix warnings coming from models #200

Merged
merged 2 commits into from
Nov 22, 2024
Merged

Fix warnings coming from models #200

merged 2 commits into from
Nov 22, 2024

Conversation

rosswhitfield
Copy link
Member

@rosswhitfield rosswhitfield commented Nov 21, 2024

Description of the changes

This fixes the two different types of warning seen coming from the models

dasmon.ActiveInstrument.instrument_id: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
	HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.
dasmon.ActiveInstrument: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
	HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

If you check the logs the warning should no longer be there docker logs data_workflow-webmon-1

The change from ForeignKey(unique=True, ..) to OneToOneField doesn't require a migration as the created table is identical.

Check all that apply:

  • updated documentation
  • Source added/refactored
  • Added unit tests
  • Added integration tests
  • (If applicable) Verified that manual tests requiring the /SNS and /HFIR filesystems pass without fail

References:

Manual test for the reviewer

(Instructions for testing here)

Check list for the reviewer

  • best software practices
    • clearly named variables (better to be verbose in variable names)
    • code comments explaining the intent of code blocks
  • All the tests are passing
  • The documentation is up to date
  • code comments added when explaining intent

@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.78%. Comparing base (25b14b4) to head (c6b6864).

Additional details and impacted files
@@           Coverage Diff           @@
##             next     #200   +/-   ##
=======================================
  Coverage   77.78%   77.78%           
=======================================
  Files          54       54           
  Lines        4708     4709    +1     
=======================================
+ Hits         3662     3663    +1     
  Misses       1046     1046           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@backmari
Copy link
Contributor

backmari commented Nov 21, 2024

For the ForeignKey(unique=True) issue, maybe we should follow the hint and make it a OneToOneField to ensure that the field is still unique in the table, in case some functionality relies on that.
For example for the model InstrumentStatus we could end up with multiple status entries for an instrument if there is no constraint for the field Instrument to be unique.

@backmari backmari merged commit 462ed48 into next Nov 22, 2024
4 checks passed
@backmari backmari deleted the fix_model_warnings branch November 22, 2024 15:31
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