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.

__fields_set__ incorrectly set unless using the validate class method

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 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:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
tiangolocommented, Aug 27, 2022

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. 🎉

1reaction
Maffelscommented, Nov 10, 2021

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 of exclude_unset once more. Since update models specifically are usually light on inheritance, it’s a relatively painless change until the behaviour in sqlmodel.SQLModel is fixed.

Read more comments on GitHub >

github_iconTop 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 >

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