Skip to content

SerializerMethodField issue after "unique together validator" fix #9700

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

Open
simone-gasparini opened this issue May 15, 2025 · 2 comments
Open

Comments

@simone-gasparini
Copy link

simone-gasparini commented May 15, 2025

DRF version 3.16.0

After the "Fix unique together validator doesn't respect condition's fields (#9360)" merge, a SerializerMethodField named as the same of a model field goes into the HiddenField because of the unique_constraint_field is null

model.py (part)

class Repository(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4)

    prefix = models.ForeignKey(
        "RepositoryPrefix",
        related_name="repository_set",
        on_delete=CASCADE,
        blank=False,
        null=True
    )
    ...
    
    class Meta:
        unique_together = [("prefix", "name")]
        ...

serializer.py

class RepositorySerializer(serializers.ModelSerializer):
    prefix = serializers.SerializerMethodField()
    ...

    def get_prefix(self, obj):
        return obj.prefix.name if obj.prefix else None
@simone-gasparini
Copy link
Author

DRF version 3.15.2 works fine

@auvipy
Copy link
Member

auvipy commented May 19, 2025

@kalekseev would you mind taking a look, please?

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

No branches or pull requests

2 participants