-
First Check
Commit to Help
Example Codefrom typing import Optional, List from sqlmodel import Field, SQLModel, Column, ARRAY, String from datetime import datetime # This is a very basic model with more field and functions valid for all tables in this project class HeroBase(SQLModel): id: Optional[int] = Field(default=None, primary_key=True) name: str = Field(index=True) secret_name: Optional[List[str]] = Field(sa_column=Column(ARRAY(String))) # <---- age: Optional[int] = Field(default=None, index=True) # This is a first aproximation of one type of table in the project (still could be a model for more projects) class Model_A(HeroBase): favorite_color: Optional[str] = Field(max_length=12, default=None) # This is also a first aproximation of one type of table in the project (still could be a model for more projects) class Model_B(HeroBase): favorite_car: Optional[int] = Field(default=None) # This is an especific table of this especific project class FirstGeneralHero(Model_A, table=True): dateOfBorn: datetime = Field(default=datetime.utcnow()) # This is another especific table of this especific project class SecodGeneralHero(Model_B, table=True): aField: str = Field(default='hello') DescriptionBefore I update to SQLModel 0.014, this kind of code run good. But now, when second table gonna be read, this error jump: "sqlalchemy.exc.ArgumentError: Column object 'secret_name' already assigned to Table 'firstgeneralhero'" I think the problem is over the field "secret_name", because it is an Array type and use sa_column. If you transform it into a string field, error disappear. It is my fault or it could be a bug or similar? Thanks!! Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.014 Python Version3.12.0 Additional ContextTo produce de error, just create virtual environment and "pip3 install SQLModel".ç pip3 list: annotated-types 0.6.0 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Code run using "sa_type" instead "sa_column".
|
Beta Was this translation helpful? Give feedback.
-
I'm hitting this error myself. In my opinion, the issue seems to be that the sqlalchemy Column instance is being reused instead of copied to a new table when a Column instance is specified through sa_column. There doesn't seem to be a "column factory" alternative. |
Beta Was this translation helpful? Give feedback.
-
Same issue. In my case I can't switch to just using sa_type
|
Beta Was this translation helpful? Give feedback.
-
In newer versions of Maybe changing the type-hint for |
Beta Was this translation helpful? Give feedback.
Code run using "sa_type" instead "sa_column".