-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Warnings on schema generation for Writable Serializers #12256
Labels
beta
Concerns a bug/feature in a beta release
status: accepted
This issue has been accepted for implementation
type: housekeeping
Changes to the application which do not directly impact the end user
Comments
amhn
added
the
type: bug
A confirmed report of unexpected behavior in the application
label
Apr 14, 2023
As far as I can see this is because the fields are overwritten in NetboxAutoSchema. Because of that the type information and the read_only-Property seems to gets lost. One possibility to get rid of the warning, is to drop read_only fields in the writable serializers: diff --git a/netbox/core/api/schema.py b/netbox/core/api/schema.py
index 0b44a3d52..b5b21d67f 100644
--- a/netbox/core/api/schema.py
+++ b/netbox/core/api/schema.py
@@ -149,9 +149,12 @@ class NetBoxAutoSchema(AutoSchema):
def get_writable_class(self, serializer):
properties = {}
+ remove_fields = []
fields = {} if hasattr(serializer, 'child') else serializer.fields
for child_name, child in fields.items():
+ if 'read_only' in dir(child) and child.read_only:
+ remove_fields.append(child_name)
if isinstance(child, (ChoiceField, WritableNestedSerializer)):
properties[child_name] = None
elif isinstance(child, ManyRelatedField) and isinstance(child.child_relation, SerializedPKRelatedField):
@@ -165,7 +168,10 @@ class NetBoxAutoSchema(AutoSchema):
meta_class = getattr(type(serializer), 'Meta', None)
if meta_class:
ref_name = 'Writable' + self.get_serializer_ref_name(serializer)
- writable_meta = type('Meta', (meta_class,), {'ref_name': ref_name})
+ fields = list(meta_class.fields)
+ for p in remove_fields:
+ fields.remove(p)
+ writable_meta = type('Meta', (meta_class,), {'ref_name': ref_name, 'fields': fields})
properties['Meta'] = writable_meta
self.writable_serializers[type(serializer)] = type(writable_name, (type(serializer),), properties) This drops 2 fields from Writable*-components in the generated schema, but they were read_only anyway and should be in the model anyway
Diff: --- a/schema.yml
+++ b/schema.yml
@@ -93569,9 +93569,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
data:
type: object
additionalProperties: {}
@@ -93602,9 +93599,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
tags:
type: array
items:
@@ -94337,9 +94331,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
PatchedWritableFHRPGroupAssignmentRequest:
type: object
description: Adds support for custom fields and tags.
@@ -94683,9 +94674,6 @@ components:
mark_connected:
type: boolean
description: Treat as if a cable is connected
- wireless_link:
- type: integer
- nullable: true
wireless_lans:
type: array
items:
@@ -103563,9 +103551,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
data:
type: object
additionalProperties: {}
@@ -103599,9 +103584,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
tags:
type: array
items:
@@ -104438,9 +104420,6 @@ components:
type: integer
nullable: true
description: Remote data source
- data_file:
- type: integer
- nullable: true
required:
- content_types
- name
-104821,9 +104800,6 @@ components:
mark_connected:
type: boolean
description: Treat as if a cable is connected
- wireless_link:
- type: integer
- nullable: true
wireless_lans:
type: array
items: |
jeremystretch
added
type: housekeeping
Changes to the application which do not directly impact the end user
beta
Concerns a bug/feature in a beta release
and removed
type: bug
A confirmed report of unexpected behavior in the application
labels
Apr 14, 2023
arthanson
added a commit
that referenced
this issue
Apr 17, 2023
jeremystretch
pushed a commit
that referenced
this issue
Apr 20, 2023
jeremystretch
added
the
status: accepted
This issue has been accepted for implementation
label
Apr 20, 2023
jeremystretch
added a commit
that referenced
this issue
Apr 21, 2023
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
beta
Concerns a bug/feature in a beta release
status: accepted
This issue has been accepted for implementation
type: housekeeping
Changes to the application which do not directly impact the end user
NetBox version
v3.5-beta
Python version
3.10
Steps to Reproduce
Generate schema using, e.g.
Expected Behavior
No warnings are displayed.
Observed Behavior
Currently several warnings are displayed for dynamically generated writable serializers:
The text was updated successfully, but these errors were encountered: