Skip to content

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
Contributor

@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
Contributor

@github-actions
Copy link
Contributor

@JonasKs JonasKs changed the title ✅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
Contributor

@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
Contributor

@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 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
Contributor

@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

3 participants