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 nested serializers with unique_together relations. #2975

Merged
merged 4 commits into from Jun 1, 2015

Conversation

sheppard
Copy link
Contributor

I came across an unexpected issue when trying to create a read-only nested serializer for a related field that's part of a unique_together constraint (in vera). An extra_kwargs entry of required=True is set for the constraint, but that conflicts with read_only=True set as the nested field's kwargs.

class Meta:
validators = [<UniqueTogetherValidator(queryset=UniqueTogetherModel.objects.all(), fields=('foreign_key', 'one_to_one'))>]
""")
self.assertEqual(unicode_repr(TestSerializer()), expected)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll likely want a slightly different representation for python 2.7.
See https://github.com/sheppard/django-rest-framework/blob/read-only-nested/tests/test_model_serializer.py#L172 for example.

@xordoquy
Copy link
Collaborator

The python 2.7 compatibility put appart, this looks good to me.

@xordoquy xordoquy added the Bug label May 28, 2015
@xordoquy xordoquy added this to the 2.4.6 Release milestone May 28, 2015
@sheppard
Copy link
Contributor Author

Ok, I think I got it now, thanks for the tip.

@tomchristie
Copy link
Member

Confused - this is Milestoned as 2.4.6, but a pull request against master?

@xordoquy xordoquy modified the milestones: 3.1.3 Release, 2.4.6 Release May 28, 2015
@xordoquy
Copy link
Collaborator

@tomchristie my bad

@xordoquy
Copy link
Collaborator

xordoquy commented Jun 1, 2015

Perfect. I ensured the test failed without the correction.
Thanks for the fix.

xordoquy added a commit that referenced this pull request Jun 1, 2015
can't create nested serializers for unique_together relations
@xordoquy xordoquy merged commit e3f856f into encode:master Jun 1, 2015
@xordoquy xordoquy changed the title can't create nested serializers for unique_together relations Fix nested serializers with unique_together relations. Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants