Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to access the direction and auto_schema in MarshmallowSerializerExtension.get_name method #392

Closed
mohannad-musleh opened this issue May 19, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@mohannad-musleh
Copy link

mohannad-musleh commented May 19, 2021

is it possible to get the direction and auto_schema (or at least the ViewSet class) in MarshmallowSerializerExtension get_name methods?

I need the direction and some properties from ViewSet class to generate the name correctly. (and in some cases to solve the naming conflict issue)

@mohannad-musleh mohannad-musleh changed the title Ability to access the direction and media type in MarshmallowSerializerExtension Ability to access the direction and media type in MarshmallowSerializerExtension.get_name method May 19, 2021
@mohannad-musleh mohannad-musleh changed the title Ability to access the direction and media type in MarshmallowSerializerExtension.get_name method Ability to access the direction and auto_schema in MarshmallowSerializerExtension.get_name method May 20, 2021
@tfranzel
Copy link
Owner

tfranzel commented May 20, 2021

the fix should be easy. problem is that this breaks everybody using get_name in an extension. i failed to include a **kwargs in the beginning so that its forward compatible. i'm undecided whether the reward outweighs the risk here.

the SerializerFieldExtension.get_name is rather special but SerializerExtension.get_name might hit more users.

@tfranzel tfranzel added the enhancement New feature or request label May 20, 2021
@mohannad-musleh
Copy link
Author

@tfranzel thank you!

for now, as a workaround, I implemented a custom AutoSchema class with a custom implementation of _get_serializer_name and _get_response_for_code methods to inject/pass the data I need

@tfranzel
Copy link
Owner

awesome! i'll leave this open to gather some support from other users. if this becomes a more common pain point we can look at it again.

in the meantime i should add kwargs to future-proof this for new user from here on out.

tfranzel added a commit that referenced this issue Jul 28, 2022
1. Allows get_name with full parameters without breaking legacy code.
2. enable calling ``auto_schema.resolve_serializer`` with
   ``bypass_extensions=True`` to allow offloading component creation
@tfranzel
Copy link
Owner

so I just hit this problem without a proper way to achieve the goal. Direction was indeed needed. I found a way to safely call legacy get_name without the new arguments. Also added auto_schema, as this might be helpful and I don't want to change it again, i.e. breaking people twice. This should be rather safe but you never know.

Even got a new feature on top of that. When this is merged, your custom AutoSchema might break. Just as a heads-up

@mohannad-musleh
Copy link
Author

Cool!

I liked how you did the backward compatibility (by Checking the method signature), and I think the changes are safe (the changes should only affect the users with custom AutoSchema implemented - as I did -).

I think I can easily update my implementation to use the new signature of the get_name method.

Thank you!

tfranzel added a commit that referenced this issue Aug 5, 2022
Extend OpenApiSerializerExtension interface. #392 #705
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants