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

Updated IPAddressInterfaceSerializer to subclass WritableNestedSerial… #2300

Merged
merged 1 commit into from
Aug 3, 2018

Conversation

explody
Copy link
Contributor

@explody explody commented Aug 2, 2018

…izer

Also added readonly args to device and virtual_machine attrs to prevent unnecessary validation

Fixes:

#2299

Per @jeremystretch recommendation, I changed IPAddressInterfaceSerializer to subclass the more modern WritableNestedSerializer. Considering WritableNestedSerializer takes only a PK for write ops, and because nested attrs for device and virtual_machine were still throwing validation errors after changing the parent class, I added read_only=True args to both. This fixed the validation and I confirmed that I could alternately PATCH an address with interface values of NULL or a PK successfully.

…izer

Also added readonly args to device and virtual_machine attrs to prevent unnecessary validation
url = serializers.SerializerMethodField() # We're imitating a HyperlinkedIdentityField here
device = NestedDeviceSerializer()
virtual_machine = NestedVirtualMachineSerializer()
device = NestedDeviceSerializer(read_only=True)
Copy link
Member

@jeremystretch jeremystretch Aug 3, 2018

Choose a reason for hiding this comment

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

This serializer is used for write (POST/PATCH) operations. These fields can't be read-only.

Nevermind, ignore me.

@jeremystretch
Copy link
Member

Tests are failing for an unrelated reason. Tried the changes locally and they work. 👍

@jeremystretch jeremystretch merged commit b4f2997 into netbox-community:develop-2.4 Aug 3, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants