Skip to content

TypeError: issubclass() arg 1 must be a class when inheriting BaseModel of a class with a complex type #949

Discussion options

You must be logged in to vote

Ah! That problem is linked to an error in your model definitions.

More specifically, it's because in your Producer class you try to set a type as List[File]. But List has no type in sqlalchemy.

In SQL databases, when you want to use lists, you typically have to use a foreign_key, or sometimes a link_table.

What I usually like to do is define Create, Read and Update models for my data. That way, it's easy later if you want to get Read data with relationship attributes for example.

I would think the best way to get what you want in your case is the following:

from typing import Annotated, Optional

from sqlmodel import SQLModel, Field, Relationship


class FileCreate(SQLModel):
    name: str

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@ValiaIsNotProgrammer
Comment options

@imneedle
Comment options

Answer selected by ValiaIsNotProgrammer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
3 participants