Model.create method doesn't raise an error if it gets unexpected arg
See original GitHub issueHi, there! First of all, thanks for your amazing work!
The problem that cause feature request.
class SomeModel(models.Model):
id = fields.IntField(pk=True) # pylint: disable=invalid-name
obj = SomeModel.create(
nonexistent_field="lol"
)
The code above is executed without errors. It surprised me because I expect to see an error due to I specified the field that doesn’t exist in the model.
Describe the solution you’d like Maybe it will be good to add fields validation in the method and related methods as well?
I ready to contribute this feature if you consider it as useful. Thank for attention!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Python unittest - opposite of assertRaises? - Stack Overflow
assertRaises is a short method that basically just creates an instance of the unittest.case._AssertRaisesContext class and returns it (see ...
Read more >How to Throw Exceptions in Python - Rollbar
Here is an example of a Python code that doesn't have any syntax errors. It's trying to run an arithmetic operation on two...
Read more >doctest — Test interactive Python examples — Python 3.11.1 ...
If true, an exception is raised upon the first failure or unexpected exception in an example. This allows failures to be post-mortem debugged....
Read more >2 Error Codes and Descriptions - Oracle Help Center
Cause: The instance creation method <methodName> with no arguments does not exist, or is not accessible. Java reflection exception wrapped in TopLink ...
Read more >Test if a function throws an exception in Python - GeeksforGeeks
The unittest unit testing framework is used to validate that the code performs as designed. To achieve this, unittest supports some ...
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
I’ll have to confirm if annotations only use
_from_db()
, then we can consider adding some kind of validation to the constructor.We could probably do this by adding an
else
here: https://github.com/tortoise/tortoise-orm/blob/develop/tortoise/models.py#L668 But would need to test if it breaks anything.@madnesspie Ah you are right, With your fixed example i found same issue too. Seems like that we are now just ignoring the unexpected fields… @grigi I think raise Exception is valid here. Could you look this plz?