Fix action serialization for cross-model returns#73
Conversation
phantomii
commented
Dec 24, 2025
- Add dedicated controller for VM ip_addresses action to serialize IpAddress models
- Update routes and functional test for /v1/vms//actions/ip_addresses
- Add documentation about action result serialization nuances (ru/en/de/zh)
Summary of ChangesHello @phantomii, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical serialization issue in RESTAlchemy's action handling mechanism. Previously, actions that returned models different from the controller's primary resource would encounter Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
225718a to
e88d59c
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces new documentation, translated into multiple languages (German, English, Russian, Chinese), detailing the nuances of action result serialization in RESTAlchemy. Specifically, it addresses how serializers and resource fields are selected for actions, explaining why an action returning a different model type than its controller's __resource__ can lead to AttributeError. The documentation proposes a workaround involving a dedicated controller whose __resource__ matches the action's return type. Corresponding code changes include adding a VMIpAddressesController and VMIPAddressesAction to demonstrate this pattern, along with a new functional test to validate the correct serialization of IP addresses for a VM. A review comment points out an N+1 query problem in the VMIpAddressesController.ip_addresses method, suggesting a refactor to use an IN clause for more efficient fetching of IP addresses.
- Add dedicated controller for VM ip_addresses action to serialize IpAddress models - Update routes and functional test for /v1/vms/<uuid>/actions/ip_addresses - Add documentation about action result serialization nuances (ru/en/de/zh)
e88d59c to
b280847
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces new documentation in German, English, Russian, and Chinese, detailing the nuances of action result serialization in RESTAlchemy. The documentation clarifies that the serialization schema for action results is determined by the controller's __resource__ attribute, not the action's return type, and proposes a workaround involving a dedicated controller for actions that return different model types. Corresponding functional test changes were added, including a new VMIpAddressesController and VMIPAddressesAction to demonstrate this workaround, along with a test case to validate its correct behavior. The OpenAPI specification generation logic was also updated to properly reflect action controllers. Review feedback identified a potential N+1 query problem in the new VMIpAddressesController's ip_addresses method, suggesting a more efficient single-query approach, and a grammatical correction for the German serialization documentation.
|
|
||
| # Besonderheiten der Serialisierung von Action-Ergebnissen | ||
|
|
||
| Dieses Dokument beschreibt eine wichtige Nuance in RESTAlchemy: **wie Serializer (Packer) und das Feld-Set eines Resources bei der Verarbeitung von `actions` ausgewählt werden**, und warum eine Action, die auf einem Controller für Resource `A` definiert ist, standardmäßig *als Resource `A`* serialisiert wird – selbst wenn sie tatsächlich ein Modell `B` zurückgibt. |
There was a problem hiding this comment.
There's a small grammatical and consistency error here. The noun 'Resource' is typically treated as feminine in German ('die Ressource'), as seen in other documentation files. Therefore, 'eines Resources' should be 'einer Ressource', and for consistency, Resource should be Ressource.
| Dieses Dokument beschreibt eine wichtige Nuance in RESTAlchemy: **wie Serializer (Packer) und das Feld-Set eines Resources bei der Verarbeitung von `actions` ausgewählt werden**, und warum eine Action, die auf einem Controller für Resource `A` definiert ist, standardmäßig *als Resource `A`* serialisiert wird – selbst wenn sie tatsächlich ein Modell `B` zurückgibt. | |
| Dieses Dokument beschreibt eine wichtige Nuance in RESTAlchemy: **wie Serializer (Packer) und das Feld-Set einer Ressource bei der Verarbeitung von `actions` ausgewählt werden**, und warum eine Action, die auf einem Controller für Ressource `A` definiert ist, standardmäßig *als Ressource `A`* serialisiert wird – selbst wenn sie tatsächlich ein Modell `B` zurückgibt. |