Skip to content

How to use Pickle Type #1484

Answered by byrman
RamDurgaSai asked this question in Questions
Mar 25, 2022 · 3 comments · 1 reply
Discussion options

You must be logged in to vote

My previous answer was perhaps a bit confusing. Suppose flow is of type Foo, then your code becomes:

class Foo:
    pass


class FlowInDb(SQLModel, table=True):
    id : str = Field(primary_key=True)
    flow: Foo = Field(sa_column=Column(PickleType))
    
    class Config:
        arbitrary_types_allowed = True

Then you can insert a FlowInDb instance into the database like this:

session.add(FlowInDb(id="d4pgyYaU3nVCJgXjYu6b", flow=Foo())
session.commit()

You don't have to pickle yourself, PickleType takes care of that.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
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
Converted from issue

This discussion was converted from issue #285 on August 11, 2025 20:39.