Add validation in SQLModel.sqlmodel_update #1241
              
                Unanswered
              
          
                  
                    
                      MatthewMckee4
                    
                  
                
                  asked this question in
                Questions
              
            Replies: 3 comments
-
| It seems simillar to the issue that sqlmodel actually does not use pytantic to validate when you set  | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| have same request. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            -
| Code example can be simplified: from sqlmodel import SQLModel, Field
class Child(SQLModel):
    age: int = Field(..., lt=18)
    height: float
child = Child(age=17, height=1.5)
# Try updating with invalid data
child.sqlmodel_update({"age": "not an int", "height": "not a float"})  # DID NOT RAISE ...
print(child)
# age='not an int' height='not a float' | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
This is very short example, but here when i update the child with invalid data, it does not do any sort of validation on the updated model, this results in an invalidated instance.
It would be nice if it re-validated the class after updating it
Operating System
Linux
Operating System Details
Ubuntu 24.04
SQLModel Version
.0.22
Python Version
3.12.3
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions