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

min_ip, max_ip fields erroring despite being specified via JSON REST API #3143

Closed
wrouesnel opened this issue Aug 17, 2017 · 2 comments
Closed

Comments

@wrouesnel
Copy link

As of commit 4794c4c I'm having a problem where the JSON rest API won't let me create networks - https://22.0.0.2/api/networks/ (docker container instance of Ralph)
a request sent to

{
   "name":"test3",
   "address":"2.0.0.0/8",
   "remarks":"",
   "vlan":1,
   "dhcp_broadcast":false,
   "reserved_from_beginning":0,
   "reserved_from_end":0,
   "gateway":null,
   "network_environment":null,
   "kind":null,
   "service_env":null,
   "terminators":[

   ],
   "racks":[

   ],
   "dns_servers":[

   ],
   "min_ip":16777216,
   "max_ip":33554431
}

produces the following result:

{
  "min_ip": [
    "This field is required."
  ],
  "max_ip": [
    "This field is required."
  ]
}

This seems to be a known issue with Django REST API, and is possibly a result of min_ip and max_ip being set as non-editable in the model?

The same request works via the form request mechanism.

@wrouesnel
Copy link
Author

Traced this down a little - I can remediate by setting the min_ip and max_ip fields to be editable in the network.py model file - whatever I try to set is ignored (but still required to be present) but the code actually gets to the save handler now (which is where the override happens).

@wrouesnel
Copy link
Author

Found it - the problem is here:

unique_together = ('min_ip', 'max_ip')

The unique_together constraint enforces a required constraint for all its arguments on any attached serializer (see here: http://www.django-rest-framework.org/api-guide/validators/#uniquetogethervalidator).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants