Closed Olegt0rr closed 3 years ago
I'm not sure this is a bug. This only happens if your model doesn't have any attributes but id. Let's think: Should we expect to have a real model with only an id and no other attributes?
I'm not sure this is a bug. This only happens if your model doesn't have any attributes but id. Let's think: Should we expect to have a real model with only an id and no other attributes?
I know, it's a weird case, but why not? This behaviour is weird too (using neighboor model ID is not a good solution)
That's senseless
I found why this is happening. I was developing some tests for a tortoise-related bug fix for fastapi-crudrouter where I didn't need any field in the Model other than the PK so that I could make an FK relation. I found that the insert query is empty!
If there is no other field other than the primary key, this is what happens:
column
is empty ([]
)column
is empty self.insert_query is empty (""
instead of a "INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, value, ...);"
or something similar)0
(and not save it on the DB).This should be considered a bug, from the Zen of Python:
Errors should never pass silently.
If creating a Model with only an id
field is an error, Tortoise should raise an error.
Which doesn't make sense since this is a completely valid model/table in all supported DBs.
raise a exception is a choice
Describe the bug
Id counters depends on another models and not increases for model without additional fields.
To Reproduce
Result
Expected result
Workaround
Add another one field to Foo model
This way id counts properly!