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 auto detecting and setting nullable, allowing overrides in field #423

Merged
merged 5 commits into from
Aug 30, 2022

Conversation

JonasKs
Copy link
Contributor

@JonasKs JonasKs commented Aug 29, 2022

See #420, potentially closes it

#424 copied my code, so contributions are a bit messed up if that is merged instead of this one. I don't mind too much though, so you can close this if you'd like.

@github-actions
Copy link

📝 Docs preview for commit 7f853e6 at: https://630c8adba75f7a0e2321cc8c--sqlmodel.netlify.app

@codecov
Copy link

codecov bot commented Aug 29, 2022

Codecov Report

Merging #423 (fc62e38) into main (f9522b3) will decrease coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #423      +/-   ##
==========================================
- Coverage   97.72%   97.62%   -0.11%     
==========================================
  Files         186      187       +1     
  Lines        6201     6268      +67     
==========================================
+ Hits         6060     6119      +59     
- Misses        141      149       +8     
Impacted Files Coverage Δ
sqlmodel/main.py 84.92% <100.00%> (+0.24%) ⬆️
tests/test_nullable.py 100.00% <100.00%> (ø)
sqlmodel/sql/expression.py 74.35% <0.00%> (-23.08%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link

📝 Docs preview for commit df83c46 at: https://630c975d319afc17b0609c69--sqlmodel.netlify.app

@github-actions
Copy link

📝 Docs preview for commit d1fd2e3 at: https://630c99a7801d6f14b58c951a--sqlmodel.netlify.app

@JonasKs JonasKs changed the title ✅Add test for nullable fields ✅ Add test for nullable fields Aug 29, 2022
br-follow added a commit to br-follow/sqlmodel that referenced this pull request Aug 29, 2022
`Field` are inserting into the database as nullable. This was introduced
in
fastapi@9830ee0#r82434170
and described in fastapi#420.

Example:
```
required_field: Optional[str] = Field(nullable=False)
```

- Added a test to confirm the regression
- Fixed test by re-ordering the code that determines if a field is nullable.

Co-authored-by: Jonas Krüger Svensson <jonas-ks@hotmail.com>, building off his PR: fastapi#423

add coverage reports

run code coverage

Add more checks to the test for the regression.

Co-authored-by: Jonas Krüger Svensson <jonas-ks@hotmail.com>

Fix comment on test

Co-authored-by: Jonas Krüger Svensson <jonas-ks@hotmail.com>

Formatting, comments
Co-authored-by: Jonas Krüger Svensson <jonas-ks@hotmail.com>

Remove newline

Co-authored-by: Jonas Krüger Svensson jonas-ks@hotmail.com

remove comment

simplify test

rename variable

add missing assert
  setting an `Optional` type but passing `nullable=True` to the `Field`
  definition
- Fix the bug
@github-actions
Copy link

📝 Docs preview for commit 4ca8a40 at: https://630cd3ae95131e4649ab9d4b--sqlmodel.netlify.app

@br-follow
Copy link
Contributor

See #420, potentially closes it

#424 copied my code, so contributions are a bit messed up if that is merged instead of this one. I don't mind too much though, so you can close this if you'd like.

I have committed my changes from #424 to this PR.

@github-actions
Copy link

📝 Docs preview for commit 0253e58 at: https://630cd4c4b736cd51455110cf--sqlmodel.netlify.app

@br-follow
Copy link
Contributor

There are other cases not covered here. For example, what would you expect the nullability of this field to be:

value: Optional[str] = Field(default="default")

@tiangolo tiangolo changed the title ✅ Add test for nullable fields 🐛 Fix auto detecting and setting nullable, allowing overrides in field Aug 30, 2022
@tiangolo
Copy link
Member

Thanks @JonasKs and @br-allstreet 🙇 🚀

I added a couple of test cases, including default strings as you suggested @br-allstreet. Then I tweaked the implementation a bit more as well to properly handle those cases.

This will be available in the next release in the next hours, SQLModel 0.0.8. 🎉

@github-actions
Copy link

📝 Docs preview for commit fc62e38 at: https://630e3835f8bb537d8b6f9a9c--sqlmodel.netlify.app

@tiangolo tiangolo merged commit ae144e0 into fastapi:main Aug 30, 2022
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.

3 participants