Skip to content
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

Schema Generator: serializer field from models.DurationField with MinValueValidator produces invalid output #8063

Closed
peterthomassen opened this issue Jun 29, 2021 · 11 comments

Comments

@peterthomassen
Copy link
Contributor

I have a model with the following field:

max_age = models.DurationField(null=True, default=None, validators=[MinValueValidator(timedelta(0))])

The schema contains the following output:

        max_age:
          type: string
          nullable: true
          minimum: !!python/object/apply:datetime.timedelta
          - 0
          - 0
          - 0

This cannot be rendered by Swagger / ReDoc, leading to failures when loading the schema.

@stale
Copy link

stale bot commented Apr 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 28, 2022
@sbrandtb
Copy link

sbrandtb commented Jun 10, 2022

The problem still occurs in 3.13.1. I would guess this is related to #7641

@stale stale bot removed the stale label Jun 10, 2022
@stale
Copy link

stale bot commented Aug 11, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 11, 2022
@peterthomassen
Copy link
Contributor Author

I believe this is still current.

@stale stale bot removed the stale label Aug 11, 2022
@tomchristie
Copy link
Member

Any keen code archeologists up for digging into what's needed to resolve this?

@stale
Copy link

stale bot commented Oct 22, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 22, 2022
@peterthomassen
Copy link
Contributor Author

I believe this is still current.

@rnshaikh
Copy link
Contributor

rnshaikh commented Jun 12, 2023

I have found that as yaml Dumper convert time delta into python tag which is not renderable. so here we can add a custom representer for datetime.timedelta which converts it into 'str' tag which is similar to JSON OpenAPI Schema fix. #7641.

Dumper.add_representer(datetime.timedelta, encoders.CustomScalar.represent_timedelta)

I have created PR for this #9007.

@stale stale bot removed the stale label Jun 12, 2023
@auvipy
Copy link
Member

auvipy commented Jun 13, 2023

I have found that as yaml Dumper convert time delta into python tag which is not renderable. so here we can add a custom representer for datetime.timedelta which converts it into 'str' tag which is similar to JSON OpenAPI Schema fix. #7641.

Dumper.add_representer(datetime.timedelta, encoders.CustomScalar.represent_timedelta)

I have created PR for this #9007.

@peterthomassen can you also review the PR please?

@auvipy auvipy closed this as completed Jun 18, 2023
@auvipy auvipy added this to the 3.15 milestone Jun 18, 2023
@peterthomassen
Copy link
Contributor Author

@peterthomassen can you also review the PR please?

Sorry for being late! I looked over the PR and couldn't spot anything problematic; OTOH I'm not too familiar with schema representations, and I'm not sure how specialized types are best represented. So, superficially, lgtm.

That said, I very MUCH appreciate that DRF is seeing some movement now. Thank you very very much for working on it! <3

@auvipy
Copy link
Member

auvipy commented Jun 19, 2023

That said, I very MUCH appreciate that DRF is seeing some movement now. Thank you very very much for working on it! <3

I will put effort to it. no worries

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

No branches or pull requests

5 participants