Skip to content

feat(tags): add unique constraint to value and implement __str__#898

Draft
DarshanCode2005 wants to merge 2 commits intoNixOS:mainfrom
DarshanCode2005:micro-change-2
Draft

feat(tags): add unique constraint to value and implement __str__#898
DarshanCode2005 wants to merge 2 commits intoNixOS:mainfrom
DarshanCode2005:micro-change-2

Conversation

@DarshanCode2005
Copy link
Copy Markdown
Contributor

This PR improves data integrity and observability for the Tag model.
Changes:
src/shared/models/cve.py :

  • Added unique=True to the Tag.value field to prevent duplicate data.
  • Implemented str to return the tag's value, improving the representation in logs.

Rationale: Duplicate tags ("critical", "critical" etc.) were previously possible in the database, leading to inconsistent data. This change enforces a clean tag registry. The string representation also significantly improves the developer & admin experience by making objects identifiable by their actual text.

@fricklerhandwerk
Copy link
Copy Markdown
Collaborator

This is one of the many things we can't "just do". At the very least it would require a migration to actually deduplicate the existing data, and a change in the ingestion code to do get_or_create. But what we just the other day happened to discuss with @adekoder is that we probably want to inline that extra table into the one field that references it. There's no use case currently in sight that would benefit from a separate table, and the amount of duplication an ArrayField would incur is negligible in the grand scheme of things.

Comment thread src/shared/models/cve.py
@DarshanCode2005
Copy link
Copy Markdown
Contributor Author

Thanks for the detailed explanation, that makes sense. I agree that adding unique=True would require a data migration and is not a small change anymore. I will remove that from this PR and keep it focused on the str improvement.

We can revisit uniqueness and possible schema simplification in a separate discussion/PR.

@fricklerhandwerk fricklerhandwerk marked this pull request as draft March 21, 2026 22:52
Comment thread src/shared/models/cve.py

value = models.CharField(max_length=128)

def __str__(self) -> str:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now, were we doing that by hand anywhere in the code? If so, please use this new thing there, if not, we can close the PR. :)

@DarshanCode2005
Copy link
Copy Markdown
Contributor Author

cve_reference.html

code snippet:

      {% for tag in ref.tags %}
        <span class="tag tag-gray">{{tag.value}}</span>
      {% endfor %}

so there we can use str(tag).

@fricklerhandwerk
Copy link
Copy Markdown
Collaborator

so there we can use str(tag).

Or just {{tag}} since string coercion is done implicitly?

@DarshanCode2005
Copy link
Copy Markdown
Contributor Author

so there we can use str(tag).

Or just {{tag}} since string coercion is done implicitly?

Hmm.... I actually wrote that by mistake.

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.

2 participants