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

✨ Update GUID handling to use stdlib `UUID.hex` instead of an `int` by andrewbolster · Pull Request #26 · fastapi/sqlmodel · GitHub

Repository navigation

✨ Update GUID handling to use stdlib UUID.hex instead of an int - #26

Merged
tiangolo merged 2 commits into
fastapi:mainfrom
andrewbolster:patch-1
Aug 27, 2022
Merged

tiangolo merged 2 commits into
fastapi:mainfrom
andrewbolster:patch-1

Conversation

Copy link
Copy Markdown
Contributor

Rather than integer based serialization grandfathered in from sqlalchemy, use the stdlib UUID.hex method.

This also fixes #25

Rather than integer based serialization grandfathered in from sqlalchemy, use the stdlib [`UUID.hex`](https://docs.python.org/3/library/uuid.html#uuid.UUID.hex) method.

This also fixes fastapi#25
andrewbolster changed the title Update GUID handling use stdlib UUID.hex Update GUID handling to use stdlib UUID.hex Aug 26, 2021

hidaris commented Oct 9, 2021

Copy link
Copy Markdown

any update?

gnillev commented Oct 15, 2021

Copy link
Copy Markdown

I will just propose also adding a small test, just to catch this.

I made my own small test to catch the behaviour in a fork to fix this, before finding this pr, so you can maybe work something off of this (probably want to generalize a bit - I made it really quick just to confirm this was causing the issue):

def test_zero_padded_uuid():
    raised = None
    myid = UUID(hex='00000000000000000000000000000001')
    stored_value = GUID().process_bind_param(myid, SQLiteDialect)
    try:
        back_to_uuid = GUID().process_result_value(stored_value, SQLiteDialect)
    except ValueError as ex:
        raised = ex
    assert raised is None
    assert myid == back_to_uuid

RobertRosca added a commit to RobertRosca/sqlmodel that referenced this pull request Nov 2, 2021

Copy link
Copy Markdown
Contributor

@tiangolo - Do you have any other maintainers that can help get small PRs like this merged? I'm also up against this issue, and the PR was opened 2 months ago.

mkarbo commented Dec 2, 2021

Copy link
Copy Markdown

Any news on this?

alucarddelta commented Dec 16, 2021 •
edited
Loading

Copy link
Copy Markdown
Contributor

I am disappointed that this simple fix was not implemented in 0.0.5, as this is causes a lot of headaches when using UUID primary keys.

mkarbo commented Dec 29, 2021

Copy link
Copy Markdown

We can hope for 0.0.7 to add this @tiangolo?

Copy link
Copy Markdown

I was just about to create an issue about it and implement the exactly same solution.

Looks like SQLModel got inspired by the same source of this gist: https://gist.github.com/gmolveau/7caeeefe637679005a7bb9ae1b5e421e

IMHO I think SQLAlquemy-Utils uses a better approach when it provides additional native dialects besides postgresql, like msql and cockroachdb, and also uses the native UUID .hex property in serialization. https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/types/uuid.html#UUIDType

synodriver pushed a commit to synodriver/sqlmodel that referenced this pull request Jun 24, 2022

codecov Bot commented Aug 27, 2022 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #26 (9bb4715) into main (db3ad59) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##             main      #26   +/-   ##
=======================================
  Coverage   97.59%   97.59%           
=======================================
  Files         182      182           
  Lines        6060     6060           
=======================================
  Hits         5914     5914           
  Misses        146      146           
Impacted Files Coverage Δ
sqlmodel/sql/sqltypes.py 56.75% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

tiangolo changed the title Update GUID handling to use stdlib UUID.hex ✨ Update GUID handling to use stdlib UUID.hex instead of an int Aug 27, 2022

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit 9bb4715 at: https://630a99822de66e5008e74d00--sqlmodel.netlify.app

Copy link
Copy Markdown
Member

Great! This makes sense, thank you @andrewbolster! 🍰

And thanks everyone for the discussion! ☕

This will be available in the next version, released in the next hours, SQLModel 0.0.7. 🎉

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improper UUID serialisation dropping leading zeros ▶️ "ValueError: badly formed hexadecimal UUID string"

8 participants


Back | FazBrowse Home | New Git URL