Skip to content

Conversation

@jeremystretch
Copy link
Member

Fixes: #20585

Tweak logic in the monkey patch to handle UniqueConstraints without a condition.

@jeremystretch jeremystretch requested review from a team and jnovinger and removed request for a team October 15, 2025 16:36
@jeremystretch
Copy link
Member Author

@pheus if you're available, could you check whether this resolves the issue for you?

@pheus
Copy link
Contributor

pheus commented Oct 15, 2025

I can confirm that this fixes the issue for my case. Thanks for the fast fix!

@jnovinger
Copy link
Member

Verified with:

./manage.py shell -c "
from django.db import models
from netbox.monkey import get_unique_validators

class TestModel(models.Model):
    name = models.CharField(max_length=100)
    class Meta:
        app_label = 'test'
        constraints = [
            models.UniqueConstraint(fields=['name'], name='test_name_unique')
        ]

field = TestModel._meta.get_field('name')
try:
    validators = list(get_unique_validators('name', field))
    print(f'Fix verified - returned {len(validators)} validators')
    for v in validators:
        print(f'   Validator: {v.__class__.__name__}')
except AttributeError as e:
    print(f'Bug present: {e}')
    import traceback
    traceback.print_exc()
"

@jnovinger jnovinger merged commit c902a1c into main Oct 15, 2025
10 checks passed
@jnovinger jnovinger deleted the 20585-UniqueConstraint-exception branch October 15, 2025 17:51
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.

API Swagger crashes when a model has a single‑field UniqueConstraint without a condition (regression in monkey‑patched DRF get_unique_validators())

4 participants