Skip to content

Fix action serialization for cross-model returns#73

Open
phantomii wants to merge 1 commit intomasterfrom
actions-serealization-howto
Open

Fix action serialization for cross-model returns#73
phantomii wants to merge 1 commit intomasterfrom
actions-serealization-howto

Conversation

@phantomii
Copy link
Copy Markdown
Member

  • 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)

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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 AttributeError due to mismatched serialization schemas. The fix involves establishing a dedicated controller for such actions, ensuring that the serialization process correctly aligns with the actual return type. This change is thoroughly documented across multiple languages and validated with a new functional test, enhancing the robustness and clarity of action result serialization.

Highlights

  • Action Serialization Fix: Implemented a solution for RESTAlchemy actions that return a different model type than their parent controller's resource, preventing AttributeError during serialization.
  • Dedicated Controller Pattern: Introduced a pattern where actions returning cross-model types are bound to a dedicated controller whose __resource__ property correctly matches the returned model type.
  • Comprehensive Documentation: Added detailed documentation in German, English, Russian, and Chinese, explaining the serialization nuance, the problem symptoms, and the recommended workaround.
  • New Functional Test: Included a new functional test case to validate the correct serialization of IpAddress models returned by a VM action.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@phantomii phantomii force-pushed the actions-serealization-howto branch from 225718a to e88d59c Compare December 24, 2025 12:49
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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)
@phantomii phantomii force-pushed the actions-serealization-howto branch from e88d59c to b280847 Compare December 24, 2025 13:23
@phantomii
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants