Skip to content

pathlib.Path is probably an unsupported type #1470

Answered by strfx
matutter asked this question in Questions
Discussion options

You must be logged in to vote

Any update on this ?

I think I can live with modeling Path as str for the moment and cast it back to Path when I use the data, but something like Field(sa_column=Column(TEXT)) would obviously be much more elegant.

Can I somehow add the FastAPI fix to my code locally ?

You maybe could use a SQLAlchemy Custom Type to convert Path to / from string:

from pathlib import Path
from sqlalchemy.types import TypeDecorator, String

class PathType(TypeDecorator):
    impl = String

    def process_bind_param(self, value, dialect):
        if isinstance(value, Path):
            return str(value)
        return value

    def process_result_value(self, value, dialect):
        if value is not None:
…

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
5 participants
Converted from issue

This discussion was converted from issue #397 on August 07, 2025 18:44.