-
-
Notifications
You must be signed in to change notification settings - Fork 167
fix: replace serializers.Serializer with MonitoringDeviceDetailSerial… #744
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
shakurah
wants to merge
4
commits into
openwisp:master
Choose a base branch
from
shakurah:fix/716-removed-unused-api-fields
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b740dea
fix: replace serializers.Serializer with MonitoringDeviceDetailSerial…
shakurah 8cb6d0d
[fix] REST API: device monitoring API mentions unused fields example …
shakurah dfbca66
Merge branch 'master' into fix/716-removed-unused-api-fields
shakurah dedd8c8
Merge branch 'openwisp:master' into fix/716-removed-unused-api-fields
shakurah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
serializer_classand the explicitMonitoringDeviceDetailSerializercall on line 154 are decoupled — consider aligning themThe
get()method always explicitly constructs device detail data viaMonitoringDeviceDetailSerializer(self.instance).data(line 154), regardless ofserializer_class. This means:MonitoringApiViewMixin.get()internally callsself.get_serializer()(the standard DRF path), device data is now serialized twice per request — once by the mixin viaget_serializer()and again on line 154.return responseon line 158),super().get()is returned directly. If the mixin usesget_serializer(), this response now includesMonitoringDeviceDetailSerializerfields that weren't present before (whenserializers.Serializerwas theserializer_class), potentially changing the CSV output structure.If
MonitoringApiViewMixin.get()does not callget_serializer()and the fix is purely for drf-yasg, the existing design is simply inconsistent —get()could be refactored to useself.get_serializer(self.instance)instead of hardcoding the class, so that both schema inference and runtime behaviour share a single source of truth:♻️ Suggested alignment (contingent on mixin behaviour)
if not request.query_params.get("csv"): charts_data = dict(response.data) - device_metrics_data = MonitoringDeviceDetailSerializer(self.instance).data + device_metrics_data = self.get_serializer(self.instance).data return Response( {**device_metrics_data, **charts_data}, status=status.HTTP_200_OK )Also applies to: 144-158
🤖 Prompt for AI Agents
🧩 Analysis chain
🏁 Script executed:
Repository: openwisp/openwisp-monitoring
Length of output: 7739
🏁 Script executed:
Repository: openwisp/openwisp-monitoring
Length of output: 24141
🏁 Script executed:
Repository: openwisp/openwisp-monitoring
Length of output: 1608
🏁 Script executed:
Repository: openwisp/openwisp-monitoring
Length of output: 2682
drf-yasg will incorrectly document POST and GET schemas — the plain JSON schema dict does not override serializer-based schema generation
The
schema = schemaassignment (line 125) is a plain JSON schema dict fromopenwisp_monitoring/device/schema.py, not a drf-yasgAutoSchemasubclass. drf-yasg ignores plain dicts and falls back to usingserializer_classfor schema generation.This causes API documentation mismatches:
MonitoringDeviceDetailSerializerfields, but the actual payload is raw device-metrics JSON (matching the NetJSON schema structure).MonitoringDeviceDetailSerializeronly, but the actual response merges device detail data withchartsdata (line 156).MonitoringDeviceDetailSerializerbut actually returns only chart data (line 158).Clients using auto-generated swagger clients or reading the API docs will have incorrect schema expectations. Either implement a custom drf-yasg
AutoSchemasubclass that properly documents per-HTTP-method schemas, or removeserializer_classif it's not used at runtime (line 154 hardcodes the serializer independently).🤖 Prompt for AI Agents