Skip to content

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

Closed

Description

@peterthomassen

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.

Activity

  1. stale commented on Apr 28, 2022

    @stale

    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.

  2. sbrandtb commented on Jun 10, 2022

    @sbrandtb

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

  3. stale commented on Aug 11, 2022

    @stale

    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.

  4. peterthomassen commented on Aug 11, 2022

    @peterthomassen
    CollaboratorAuthor

    I believe this is still current.

  5. lovelydinosaur commented on Aug 22, 2022

    @lovelydinosaur
    Member

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

  6. stale commented on Oct 22, 2022

    @stale

    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.

  7. peterthomassen commented on Oct 24, 2022

    @peterthomassen
    CollaboratorAuthor

    I believe this is still current.

  8. rnshaikh commented on Jun 12, 2023

    @rnshaikh
    Contributor

    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.

  9. auvipy commented on Jun 13, 2023

    @auvipy
    Collaborator

    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?

  10. added this to the 3.15 milestone on Jun 18, 2023
  11. peterthomassen commented on Jun 19, 2023

    @peterthomassen
    CollaboratorAuthor

    @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

  12. auvipy commented on Jun 19, 2023

    @auvipy
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions