-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 creating schema from model using ConstrainedStr with regex str as dict key #5223
Fix creating schema from model using ConstrainedStr with regex str as dict key #5223
Conversation
please review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're trying to absolutely minimise the footprint in changes to v1, hence my suggestions.
Please update.
…_pattern function in schema.py instead
updated towards minimal footprint, please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM.
@dmontagu please review and merge if you're happy.
LGTM. I don't like using the "private"
|
Yep, it looks like the code in v2 has been refactored so this particular failure mode can't even happen. So I don't think there's anything to do in terms of implementing a similar fix in v2. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pydantic](https://togithub.com/pydantic/pydantic) | `==1.10.6` -> `==1.10.7` | [![age](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/compatibility-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/confidence-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pydantic/pydantic</summary> ### [`v1.10.7`](https://togithub.com/pydantic/pydantic/releases/tag/v1.10.7): 2023-03-22 [Compare Source](https://togithub.com/pydantic/pydantic/compare/v1.10.6...v1.10.7) #### What's Changed - Fix creating schema from model using `ConstrainedStr` with `regex` as dict key, [#​5223](https://togithub.com/pydantic/pydantic/issues/5223) by [@​matejetz](https://togithub.com/matejetz) - Address bug in mypy plugin caused by explicit_package_bases=True, [#​5191](https://togithub.com/pydantic/pydantic/issues/5191) by [@​dmontagu](https://togithub.com/dmontagu) - Add implicit defaults in the mypy plugin for Field with no default argument, [#​5190](https://togithub.com/pydantic/pydantic/issues/5190) by [@​dmontagu](https://togithub.com/dmontagu) - Fix schema generated for Enum values used as Literals in discriminated unions, [#​5188](https://togithub.com/pydantic/pydantic/issues/5188) by [@​javibookline](https://togithub.com/javibookline) - Fix mypy failures caused by the pydantic mypy plugin when users define `from_orm` in their own classes, [#​5187](https://togithub.com/pydantic/pydantic/issues/5187) by [@​dmontagu](https://togithub.com/dmontagu) - Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1` and the custom mypy plugin, [#​5162](https://togithub.com/pydantic/pydantic/issues/5162) by [@​cdce8p](https://togithub.com/cdce8p) #### New Contributors - [@​javibookline](https://togithub.com/javibookline) made their first contribution in [pydantic/pydantic#5188 - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [pydantic/pydantic#5223 **Full Changelog**: pydantic/pydantic@v1.10.6...v1.10.7 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/flux-local). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzUuMTcuMSJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pydantic](https://togithub.com/pydantic/pydantic) | `==1.10.6` -> `==1.10.7` | [![age](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/compatibility-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/pydantic/1.10.7/confidence-slim/1.10.6)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pydantic/pydantic</summary> ### [`v1.10.7`](https://togithub.com/pydantic/pydantic/releases/tag/v1.10.7): 2023-03-22 [Compare Source](https://togithub.com/pydantic/pydantic/compare/v1.10.6...v1.10.7) #### What's Changed - Fix creating schema from model using `ConstrainedStr` with `regex` as dict key, [#​5223](https://togithub.com/pydantic/pydantic/issues/5223) by [@​matejetz](https://togithub.com/matejetz) - Address bug in mypy plugin caused by explicit_package_bases=True, [#​5191](https://togithub.com/pydantic/pydantic/issues/5191) by [@​dmontagu](https://togithub.com/dmontagu) - Add implicit defaults in the mypy plugin for Field with no default argument, [#​5190](https://togithub.com/pydantic/pydantic/issues/5190) by [@​dmontagu](https://togithub.com/dmontagu) - Fix schema generated for Enum values used as Literals in discriminated unions, [#​5188](https://togithub.com/pydantic/pydantic/issues/5188) by [@​javibookline](https://togithub.com/javibookline) - Fix mypy failures caused by the pydantic mypy plugin when users define `from_orm` in their own classes, [#​5187](https://togithub.com/pydantic/pydantic/issues/5187) by [@​dmontagu](https://togithub.com/dmontagu) - Fix `InitVar` usage with pydantic dataclasses, mypy version `1.1.1` and the custom mypy plugin, [#​5162](https://togithub.com/pydantic/pydantic/issues/5162) by [@​cdce8p](https://togithub.com/cdce8p) #### New Contributors - [@​javibookline](https://togithub.com/javibookline) made their first contribution in [pydantic/pydantic#5188 - [@​matejetz](https://togithub.com/matejetz) made their first contribution in [pydantic/pydantic#5223 **Full Changelog**: pydantic/pydantic@v1.10.6...v1.10.7 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/allenporter/pyrainbird). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzUuMTcuMSJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Change Summary
Currently, schema creation fails if a model uses a ConstrainedStr model as keys in a dict:
ConstrainedStr
regex
field is typed asOptional[Union[str, Pattern[str]]
, when accessing pattern generating the schema for patternProperty,regex.pattern
is accessed.This PR contains the following changes:
ConstrainedStr._get_pattern
function inschema.py
when accessing the patternChecklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)
Selected Reviewer: @samuelcolvin