__fields_set__ incorrectly set unless using the validate class method
See original GitHub issueFirst 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 sqlmodel import SQLModel
from typing import Optional
class HeroUpdate(SQLModel):
name: Optional[str] = None
secret_name: Optional[str] = None
age: Optional[int] = None
hero = HeroUpdate(age=42)
print(hero.dict(exclude_unset=True))
# output = {'name': None, 'secret_name': None, 'age': 42}
Description
*Create a HeroUpdate model *Create a HeroUpdate instance with unset fields *Use the .dict attribute with the unset_fields parameter *unset_fields show up as None rather than not being included in the dictionary *works fine with Pydantic BaseModel instances
Operating System
macOS
Operating System Details
No response
SQLModel Version
‘0.0.4’
Python Version
3.9.0
Additional Context
If it is run as: hero = HeroUpdate.validate({‘age’:42}) the _fields_set_ are correctly set and it works
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
Top Results From Across the Web
javascript - JQuery Validate individual fieldsets - Stack Overflow
Basically, apparently validation.js only validates the visible fields by default. Here's the full example code, click through to the link to ...
Read more ><fieldset>: The Field Set element - HTML - MDN Web Docs
This attribute takes the value of the id attribute of a <form> element you want the <fieldset> to be part of, even if...
Read more >Repopulating forms, not using Fieldset class - FuelPHP forums
Labels in a fieldset are always shown if they are defined. Fieldsets will show validation errors automatically if present. There is a template...
Read more >Form Fieldsets do not allow error messages to be set. #5265
The problem is that you can't set a message for that fieldset if validation fails. This is because the Fieldset's setMessages() and getMessages ......
Read more >Documentation - jQuery Validation Plugin
A set of standard methods is available, and it is easy to write your own. rule: A validation rule associates an element with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This was solved by @statt8900 in https://github.com/tiangolo/sqlmodel/pull/117, it will be available in SQLModel
0.0.7
, released in the next hours. 🎉I have the same problem in my project during development on windows. (SQLModel 0.0.4)
Currently, a workaround might be using the original
pydantic.BaseModel
as the base model for specific update models allows for the use ofexclude_unset
once more. Since update models specifically are usually light on inheritance, it’s a relatively painless change until the behaviour insqlmodel.SQLModel
is fixed.