FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Possibility to change default Pydantic to SQLAlchemy mappings by sambadi · Pull Request #800 · fastapi/sqlmodel · GitHub

Repository navigation

Possibility to change default Pydantic to SQLAlchemy mappings - #800

Closed
sambadi wants to merge 5 commits into
fastapi:mainfrom
sambadi:feature/sa_model_type_mapping
Closed

sambadi wants to merge 5 commits into
fastapi:mainfrom
sambadi:feature/sa_model_type_mapping

Conversation

sambadi commented Feb 12, 2024

Copy link
Copy Markdown

Hello folks!
First of all i want to apologise for my bad english )
So i want to present two features realised for my project and what i want to share with community:
1)To be allow to change default Python to SqlAlchemy types mapping
2) To be allow to store Pydantic model data as Json at database (with ability to use SQLAlchemy Mutable wrap)

Possible is closes issue #503, but not sure

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 6b5f287 at: https://6b70ec7d.sqlmodel.pages.dev

sambadi commented Feb 12, 2024 •
edited
Loading

Copy link
Copy Markdown
Author

Looks like in new version of pydantic (2.6.1) added some breaking changes. All completed tests at MR pipeline was started with previous stable version of pydantic - 2.5.3

This commit at Pydantic.main totally breaks the eq behaviour

pydantic/pydantic@62ed0aa#diff-8708af8d26c26644976866f974e0b810b0940ede43ff487e457057d5a1f07999

See discussion about _eq at #761

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit fb58b86 at: https://db9f51b8.sqlmodel.pages.dev

alejsdev added the feature New feature or request label Jul 12, 2024

Copy link
Copy Markdown

That looks interesting. I'm using Pydantic's NaiveDatetime, and since it isn't a subclass of datetime.datetime I have to pass sa_type=saDateTime (from sqlalchemy import DateTime as saDateTime) on every field. Otherwise get_sqlalchemy_type() wouldn't know how to handle this type in the database.

However I think this case should be handled internally by SQLModel and without requiring extra code since SQLModel already depends on Pydantic and could just as well support these types.

github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 5, 2025

github-actions Bot commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

YuriiMotov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@sambadi, thank you for your interest and efforts!

So, the idea of this PR is that instead of having a bunch of IFs in get_sqlalchemy_type we can create a sa_types_map dict where we can store all mapping information. Then in get_sqlalchemy_type we would iterate through sa_types_map and choose the correct type if present.

This will allow users to re-map type for their apps in one place instead of providing sa_type for every field of that type.

I personally like the idea in general.
Let's wait for Sebastian to validate the idea

Copy link
Copy Markdown

@sambadi, thanks for implementing this! I considered doing it myself one day, but now I don't have to. ❤️
Could you please rebase the branch and resolve the conflicts so we can move on easier?

sambadi commented Nov 25, 2025

Copy link
Copy Markdown
Author

@sambadi, thanks for implementing this! I considered doing it myself one day, but now I don't have to. ❤️ Could you please rebase the branch and resolve the conflicts so we can move on easier?

I'll try, but not sure that can find enough time =(

fbuccioni commented Oct 1, 2026 •
edited
Loading

Copy link
Copy Markdown

Hey everyone!

I am looking for this feature without have to monkeypatch as in my comment referred to this PR (#1967 #503), so I fork the branch and update it to the last changes, you can see it in fbuccioni/sqlmodel:sa_model_type_mapping I try submitting the PR to the original author @sambadi in the following PR but haven't answer so I post it in the original PR, tell me if something additional is needed.

Thanks in advance

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL