Raise a helpful error if Table=True
is passed instead of table
#704
Unanswered
JamesHutchison
asked this question in
Questions
Replies: 0 comments
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.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I was writing a model definition and using GitHub Copilot.
Copilot suggested
Table=True
as the keyword argument instead of the correcttable=True
. I failed to notice this when I accepted the suggestion.After various other changes, I got around to finally testing the model with a relationship. I get a cryptic error about the name of my model not being mapped. The error comes from the relationship line itself, so it gives the impression that maybe I did that wrong somehow.
I check my imports and realize I forgot to add it an import to the
__init__.py
for the models.The error persists.
I ask GPT-4 to find something wrong with my code and it says it looks good.
I spend a bunch of time checking imports, commenting things out, I set breakpoints and confirm my file is getting imported correctly. I check the database and notice that it for some reason really hates my model and refuses to acknowledge it.
I finally get around to setting a breakpoint in the metaclass and determine that it really is executing. Eventually, after A/B stepping through the logic between a working and the non-working model, I see that it's missing the table config.
I finally notice that its a capital
T
instead of lowercaset
.This could have been easily avoided. Its not clear to me why I would create a class that inherits from
SQLModel
and not have it be a table. The only reason I can tell is that its to differentiate from the base class or a possible user base class.At the very least, passing
Table
(capitalized) should raise a helpful error. Defining__tablename__
but not settingtable=True
also feels like an error case.Operating System
Linux
Operating System Details
N/A
SQLModel Version
0.0.11
Python Version
3.11.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions