question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Field(nullable=True)` is ignored due to recent changes released in version 0.0.7

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google “How to X in SQLModel” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional

from sqlmodel import Field, Session, SQLModel, create_engine

class Hero(SQLModel, table=True):
  id: Optional[int] = Field(default=None, primary_key=True)
  # This should not be nullable
  name: Optional[str] = Field(default=None, nullable=False)

hero = Hero()
engine = create_engine("sqlite:///database.db")

SQLModel.metadata.create_all(engine)
with Session(engine) as session:
  session.add(hero)
  session.commit()
  session.refresh(hero)
  print(hero)

Description

  • Create a hero model with a non-nullable column by assigning it to Field(nullable=True)
  • Create a hero instance without setting the column
  • Save the instance to the DB. Should get an error but the hero instance saves successfully.

I believe this issue was introduced here: https://github.com/tiangolo/sqlmodel/commit/9830ee0d8991ffc068ffb72ccead2427c84e58ee#r82434170

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.7

Python Version

Python 3.10.5

Additional Context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
br-allstreetcommented, Aug 29, 2022

I assumed @tiangolo would squash the commits before merging the PR. But I will commit to your PR.

0reactions
github-actions[bot]commented, Sep 10, 2022

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm install fails with NPM 7 #19957 - angular/angular-cli
Creating a new Angular project with the Angular CLI ( ng new ) fails when using the latest version of npm (7.5.x). Error...
Read more >
Change nullable property of column in spark dataframe
I want to make 'nullable = true' for each one of these variable. How do I declare that from the start or switch...
Read more >
typeorm: CHANGELOG
This change is due to type-safety improvement new where signature brings. order in FindOptions (used in find* methods) doesn't support ordering by relations ......
Read more >
Fix / Feature List for IBM Financial Transaction Manager ...
Content. The following is a complete list of the fixes and features for FTM V3. 0.0, with the most recent fix first. AuxStatus...
Read more >
npm fails to install - Google Groups
Or are you trying to launch an Appium\nserver from a script with a custom app? If so you can start Appium without\ngrunt from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found