Skip to content

Added schema generation for Generic fields - #2262

Merged
samuelcolvin merged 14 commits into
pydantic:masterfrom
maximberg:master
Feb 13, 2021
Merged

samuelcolvin merged 14 commits into
pydantic:masterfrom
maximberg:master

Conversation

@maximberg

@maximberg maximberg commented Jan 14, 2021 •

Copy link
Copy Markdown
Contributor

Change Summary

Generating schema for generic fields hasn't been implemented. Now it should work.

Related issue number

Fixes #1578.

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)

@codecov

codecov Bot commented Jan 14, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #2262 (bf9e4df) into master (13a5c7d) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #2262   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         4199      4205    +6     
  Branches       854       856    +2     
=========================================
+ Hits          4199      4205    +6     
Impacted Files Coverage Δ
pydantic/typing.py 100.00% <ø> (ø)
pydantic/schema.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13a5c7d...bf9e4df. Read the comment docs.

@PrettyWood

Copy link
Copy Markdown
Contributor

Hi @maximberg and thanks for the contribution.
I don't know if you saw but #2260 was opened yesterday and tackles the same issue.
Probably good to merge both works!

@maximberg

maximberg commented Jan 14, 2021 •

Copy link
Copy Markdown
Contributor Author

Hi @PrettyWood,
I didn't see your pull request yesterday. See what you can add to mine if it's not difficult for you. Tests passed, but coverage decreased.
Thanks )

@maximberg

Copy link
Copy Markdown
Contributor Author

Coverage restored.

@dashavoo dashavoo mentioned this pull request Jan 14, 2021
1 of 4 tasks
Comment thread pydantic/schema.py Outdated
@PrettyWood

PrettyWood commented Jan 19, 2021 •

Copy link
Copy Markdown
Contributor

I didn't see your pull request yesterday. See what you can add to mine if it's not difficult for you. Tests passed, but coverage decreased.

As a matter of fact it's not my PR but @danni's. I just think both works should be merged into one. If this PR is good to go and test cases from @danni's PR are green with your PR fine! But I won't checkout locally both works and do it myself sorry

Co-authored-by: Maz Jaleel <mazjaleel@gmail.com>
@maximberg

Copy link
Copy Markdown
Contributor Author

@Mazyod Thanks! I used your proposal.

@maximberg

maximberg commented Jan 21, 2021 •

Copy link
Copy Markdown
Contributor Author

@PrettyWood Actually @danni's PR is not exactly about problem, described in #1578.

@Mazyod

Mazyod commented Feb 5, 2021

Copy link
Copy Markdown
Contributor

@samuelcolvin I wanted to sponsor this project because recent generics enhancements will make a big difference for our project 🙇‍♂️ Appreciate your help

@davidhyman

Copy link
Copy Markdown

👍 here too

I have tried out both #2262 (this) and #2260 MRs and they both work well with my codebase 😄

Currently @danni's MR is indicating lower code coverage. However, two of those tests flag failures on @maximberg's MR (test_nested_generic, test_complex_nested_generic), and I see (but don't fully comprehend) the diff between them.

By way of expediency, perhaps this MR could be merged as-is, providing an improvement? A later MR would then add the nested generic functionality.

In the meantime I will attempt to understand both MRs...

@maximberg

Copy link
Copy Markdown
Contributor Author

@davidhyman My code solves the problem of generic fields in generating schema.
@danni tries to solve the problem of nested generic models.
In my project I want to use generic fields and I made necessary changes here.

@maximberg

maximberg commented Feb 12, 2021 •

Copy link
Copy Markdown
Contributor Author

I found some strange behavior when generic field is Optional. Will check it on Monday, 15th.

@samuelcolvin
samuelcolvin merged commit c3870b6 into pydantic:master Feb 13, 2021
@samuelcolvin

Copy link
Copy Markdown
Member

this looks great, thank you.

If you find other strange behaviour, please create an issue or if you're confident, a PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseModel.schema() fails when using generic types

5 participants