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.

Model.create method doesn't raise an error if it gets unexpected arg

See original GitHub issue

Hi, 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:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, May 5, 2020

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.

1reaction
lntuitioncommented, May 5, 2020

@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?

Read more comments on GitHub >

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

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