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

Fix incorrect subclass check for secretstr #6730

Conversation

AlexVndnblcke
Copy link
Contributor

@AlexVndnblcke AlexVndnblcke commented Jul 18, 2023

Currently subclasses of SecretStr fail to evaluate self.field_type is SecretStr and default to bytes_type. This is not how it should go as the subclass explicitly subclasses the SecretStr type.

This fix tests if the type is of SecretStr with issubclass which states:

A class is considered a subclass of itself

Which makes is backwards compatible for the actual SecretStr as well.

Change Summary

Allow pydantic scheme creation to work with subclasses of SecretStr

Related issue number

fix #6729

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @davidhewitt

@AlexVndnblcke AlexVndnblcke force-pushed the fix-incorrect-subclass-check-for-secretstr branch from 5cdbfca to 04be64b Compare July 18, 2023 09:04
Currently subclasses of SecretStr fail to evaluate
`self.field_type is SecretStr` and default to `bytes_type`. This is not
how it should go as the subclass explicitly subclasses the SecretStr
type.

This fix tests if the type is of SecretStr with `issubclass` which
states:

>  A class is considered a subclass of itself

Which makes is backwards compatible for the actual SecretStr as well.
@AlexVndnblcke AlexVndnblcke force-pushed the fix-incorrect-subclass-check-for-secretstr branch from 04be64b to c6a25ad Compare July 18, 2023 09:38
@AlexVndnblcke
Copy link
Contributor Author

please review

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, this fix looks correct to me 👍

@davidhewitt davidhewitt merged commit 66251f8 into pydantic:main Jul 18, 2023
47 checks passed
Kludex pushed a commit to Kludex/pydantic that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subclass of SecretStr expects bytes as input
2 participants