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

Empty string is a valid JSON-key #4252

Merged

Conversation

SergeyTsaplin
Copy link
Contributor

@SergeyTsaplin SergeyTsaplin commented Jul 19, 2022

Change Summary

An empty string is a valid JSON attribute name, so aliases checking cannot be just like bool(alias) it should be strictly compared with None.

Related issue number

fix #4253

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Signed-off-by: Sergey Tsaplin <me@sergeytsaplin.com>
@SergeyTsaplin SergeyTsaplin force-pushed the empty-string-is-valid-json-key branch from 04a0fc7 to c82d286 Compare July 19, 2022 11:27
@SergeyTsaplin SergeyTsaplin marked this pull request as ready for review July 19, 2022 11:28
@samuelcolvin
Copy link
Member

Thanks for the contribution.

While I think you're technically correct. I'm not sure I would support changing this at this late stage for pydantic V1.

I believe this is fixed in pydantic-core (the basis for pydantic V2) - if you're willing, it would be very useful to add unit tests for this to pydantic-core?

The plan is to get v1.10 released with mostly cosmetic changes and some new features that having been hanging around for a long time, then move ahead with V2.

What do others think? @PrettyWood @hramezani

@hramezani
Copy link
Member

Thanks @SergeyTsaplin for the patch 👍 and Thanks @samuelcolvin for explaining and asking my opinion.

I'm not sure I would support changing this at this late stage for pydantic V1.

Why would be the problem? seems we don't need a big change to support it?

it would be very useful to add unit tests for this to pydantic-core

👍

@samuelcolvin
Copy link
Member

ye, I agree it's a small change. Just there's a lot in fields.py that scares me, its pretty complicated. My worry is subtle side-effects not covered tests, but maybe I'm being a wimp. ✋

Let's wait and see what @PrettyWood thinks.

@SergeyTsaplin
Copy link
Contributor Author

@samuelcolvin I don't think that the change will break some existed code, it can break only when a user uses Field(alias='') for not "aliased" fields (I have no idea why to do it:)), but of course, the final decision is up to you. For me, it's not a problem to wait for 1.11 if you accidentally decide to merge it to the V1.

About the unit-test to pydantic-core - I can do it, but not soon. It may take me a few days to find a time for it.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

Let's go ahead with this.

changes/4253-sergeytsaplin.md Outdated Show resolved Hide resolved
@samuelcolvin
Copy link
Member

About the unit-test to pydantic-core - I can do it, but not soon. It may take me a few days to find a time for it.

No problem with a wait, this is a marathon, not a sprint.

SergeyTsaplin and others added 2 commits July 19, 2022 13:50
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
…arison with None

Signed-off-by: Sergey Tsaplin <me@sergeytsaplin.com>
@SergeyTsaplin
Copy link
Contributor Author

By the way, I found one more place where I missed the correct condition. Should I squash all the commits to a single one?

@samuelcolvin
Copy link
Member

no, just keep committing, we squash on merge.

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

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

Looks good! I don't see any risk for this in v1.10

@SergeyTsaplin
Copy link
Contributor Author

So, I believe it's absolutely ready, so please review.

@hramezani
Copy link
Member

Let's wait for @samuelcolvin for final review and probably merge.

@samuelcolvin samuelcolvin merged commit 9cfbd2b into pydantic:master Aug 3, 2022
@samuelcolvin
Copy link
Member

thanks so much.

@samuelcolvin
Copy link
Member

Well (while I still think this is okay to be included in v1.10), my paranoia was well placed, tis was breaking starlite, see litestar-org/litestar#402.

Basically with pydantic v1's massive public (or semi-public) API, basically every change can break something. Bring on V2.

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.

An empty string is a valid JSON attribute name
4 participants