René's URL Explorer Experiment


Title: Improper UUID serialisation dropping leading zeros ▶️ "ValueError: badly formed hexadecimal UUID string" · Issue #25 · fastapi/sqlmodel · GitHub

Open Graph Title: Improper UUID serialisation dropping leading zeros ▶️ "ValueError: badly formed hexadecimal UUID string" · Issue #25 · fastapi/sqlmodel

X Title: Improper UUID serialisation dropping leading zeros ▶️ "ValueError: badly formed hexadecimal UUID string" · Issue #25 · fastapi/sqlmodel

Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I already searched in Google "How to X in...

Open Graph Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...

X Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated searc...

Opengraph URL: https://github.com/fastapi/sqlmodel/issues/25

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improper UUID serialisation dropping leading zeros ▶️ \"ValueError: badly formed hexadecimal UUID string\"","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nimport uuid\r\nfrom typing import Optional\r\n\r\nimport sqlalchemy.exc\r\nfrom sqlmodel import SQLModel, Field\r\nfrom sqlmodel import create_engine, Session, select\r\n\r\n\r\nclass Hero(SQLModel, table=True):\r\n    id: Optional[uuid.UUID] = Field(primary_key=True,\r\n                                    default_factory=uuid.uuid4)\r\n    name: str\r\n    secret_name: str\r\n    age: Optional[int] = None\r\n\r\n    def __str__(self):\r\n        return f'{self.name} (AKA {self.secret_name}) [{self.age if self.age is not None else \"Unknown\"}]'\r\n\r\n\r\nsqlite_file_name = \"database.db\"\r\nsqlite_url = f\"sqlite:///{sqlite_file_name}\"\r\n\r\nengine = create_engine(sqlite_url, echo=True)  # remove echo for prod\r\n\r\n\r\ndef create_db_and_tables():\r\n    try:\r\n        Hero.__table__.drop(engine)\r\n    except sqlalchemy.exc.OperationalError:  # table doesn't exist yet\r\n        pass\r\n    SQLModel.metadata.create_all(engine)\r\n\r\n\r\ndef create_heroes():\r\n    heros = [\r\n        Hero(name=\"Deadpond\", secret_name=\"Dive Wilson\"),\r\n        Hero(name=\"Spider-Boy\", secret_name=\"Pedro Parqueador\"),\r\n        Hero(name=\"Rusty-Man\", secret_name=\"Tommy Sharp\", age=48),\r\n        Hero(name=\"Tarantula\", secret_name=\"Natalia Roman-on\", age=32),\r\n        Hero(name=\"Black Lion\", secret_name=\"Trevor Challa\", age=35),\r\n        Hero(name=\"Dr. Weird\", secret_name=\"Steve Weird\", age=36),\r\n        Hero(name=\"Captain North America\", secret_name=\"Esteban Rogelios\", age=93),\r\n    ]\r\n\r\n    with Session(engine) as session:\r\n        for hero in heros:\r\n            session.add(hero)\r\n        session.commit()\r\n\r\n\r\ndef select_heroes():\r\n    with Session(engine) as session:\r\n        for hero in session.exec(select(Hero)):\r\n            print(hero.id)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    while True:\r\n        try:\r\n            create_db_and_tables()\r\n            create_heroes()\r\n            select_heroes()\r\n        except ValueError:\r\n            raise\r\n```\r\n\r\n#### Cleansed Traceback\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File “/…/sqlmodel_tutorial/minimal_example.py\", line 89, in \u003cmodule>\r\n    select_heroes()\r\n  File “/…/sqlmodel_tutorial/minimal_example.py\", line 80, in select_heroes\r\n    for hero in session.exec(select(Hero)):\r\n  File \"/.../lib/python3.8/site-packages/sqlalchemy/engine/result.py\", line 381, in iterrows\r\n    for row in self._fetchiter_impl():\r\n  File \"/.../lib/python3.8/site-packages/sqlalchemy/orm/loading.py\", line 147, in chunks\r\n    fetch = cursor._raw_all_rows()\r\n  File \"/.../lib/python3.8/site-packages/sqlalchemy/engine/result.py\", line 392, in _raw_all_rows\r\n    return [make_row(row) for row in rows]\r\n  File \"/.../lib/python3.8/site-packages/sqlalchemy/engine/result.py\", line 392, in \u003clistcomp>\r\n    return [make_row(row) for row in rows]\r\n  File \"/.../lib/python3.8/site-packages/sqlalchemy/sql/type_api.py\", line 1430, in process\r\n    return process_value(value, dialect)\r\n  File \"/.../lib/python3.8/site-packages/sqlmodel/sql/sqltypes.py\", line 61, in process_result_value\r\n    value = uuid.UUID(value)\r\n  File “/…/lib/python3.8/uuid.py\", line 171, in __init__\r\n    raise ValueError('badly formed hexadecimal UUID string')\r\nValueError: badly formed hexadecimal UUID string\r\n```\r\n\r\n\r\n### Description\r\n\r\nRunning through the tutorial up until around [this point](https://sqlmodel.tiangolo.com/tutorial/select/), I tried swapping out the `int` id key for a `UUID` key.\r\n\r\nThis works _except_ whenever the `uuid.uuid4` default factory creates a UUID with a hexstring that starts with a zero. \r\n\r\nIt appears that [here](https://github.com/tiangolo/sqlmodel/blob/02da85c9ec39b0ebb7ff91de3045e0aea28dc998/sqlmodel/sql/sqltypes.py#L52) in `sqltypes.py` that, rather than using [`UUID().hex`](https://docs.python.org/3/library/uuid.html#uuid.UUID.hex), `sqltypes.py` carries on sqlalchemy's [integer stringification apprach](https://docs.sqlalchemy.org/en/14/core/custom_types.html?highlight=guid#backend-agnostic-guid-type), however, doesn't include any padding declaration.\r\n\r\nIMO there are two options; \r\n1. faithfully fix the replication of SQLAlchemy's `UUID` ▶️ `int` ▶️ `str` approach with the padding fixed (`f\"{v.int:032x}\"`)\r\n2. switch to using the stdlib `UUID.hex` implementation for serialisation\r\n\r\nPersonally I'm a fan of the latter so will spin up a PR \r\n\r\n### Operating System\r\n\r\nmacOS\r\n\r\n### Operating System Details\r\n\r\n_No response_\r\n\r\n### SQLModel Version\r\n\r\n0.0.4\r\n\r\n### Python Version\r\n\r\n3.8.8\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/andrewbolster","@type":"Person","name":"andrewbolster"},"datePublished":"2021-08-26T05:55:25Z","url":"https://github.com/fastapi/sqlmodel/issues/25"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:59128df7-b619-877c-6dbe-fb629fe0ad4c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC4B0:3D7683:44F4DB:61D9D9:6AFDEA6F
html-safe-nonceee37753783f52931fb5e9dbaf87c95587db4189c8c4d8fb0c37a131a345b0a2f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEIwOjNENzY4Mzo0NEY0REI6NjFEOUQ5OjZBRkRFQTZGIiwidmlzaXRvcl9pZCI6IjczODc4NTk0NjA1MjMxNTgxMjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8087f395c11ba52b2f69ebdbfb2a00b3df81ae9947614a62edc872bde1d62969
hovercard-subject-tagissue:979863543
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/25/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9f67d1512db5fafce7ea7421e0182cbc7cb7b0f2a7f71b8f4a6e1093acdbc368/fastapi/sqlmodel/issues/25
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9f67d1512db5fafce7ea7421e0182cbc7cb7b0f2a7f71b8f4a6e1093acdbc368/fastapi/sqlmodel/issues/25
og:image:altFirst Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameandrewbolster
hostnamegithub.com
expected-hostnamegithub.com
None91ef1a291a064ac31ac459ab3f75261dbdd924c41ea5bd027e591c5b46cc9ce7
turbo-cache-controlno-preview
go-importgithub.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git
octolytics-dimension-user_id156354296
octolytics-dimension-user_loginfastapi
octolytics-dimension-repository_id399495186
octolytics-dimension-repository_nwofastapi/sqlmodel
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id399495186
octolytics-dimension-repository_network_root_nwofastapi/sqlmodel
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released62bc98ce2346f4006e4a2810e9e22f37e7e6422
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/fastapi/sqlmodel/issues/25#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F25
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F25
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=fastapi%2Fsqlmodel
Reloadhttps://github.com/fastapi/sqlmodel/issues/25
Reloadhttps://github.com/fastapi/sqlmodel/issues/25
Reloadhttps://github.com/fastapi/sqlmodel/issues/25
fastapihttps://github.com/fastapi
sqlmodelhttps://github.com/fastapi/sqlmodel
Codehttps://github.com/fastapi/sqlmodel
Issues1 (1)https://github.com/fastapi/sqlmodel/issues
Pull requests53 (53)https://github.com/fastapi/sqlmodel/pulls
Discussionshttps://github.com/fastapi/sqlmodel/discussions
Actionshttps://github.com/fastapi/sqlmodel/actions
Projectshttps://github.com/fastapi/sqlmodel/projects
Security and qualityhttps://github.com/fastapi/sqlmodel/security
Insightshttps://github.com/fastapi/sqlmodel/insights
https://github.com/fastapi/sqlmodel
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/25
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/25
Improper UUID serialisation dropping leading zeros ▶️ "ValueError: badly formed hexadecimal UUID string"https://github.com/fastapi/sqlmodel/issues/25#top
#26https://github.com/fastapi/sqlmodel/pull/26
bugSomething isn't workinghttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/andrewbolster
andrewbolsterhttps://github.com/andrewbolster
on Aug 26, 2021https://github.com/fastapi/sqlmodel/issues/25#issue-979863543
Pydantichttps://github.com/samuelcolvin/pydantic
SQLAlchemyhttps://github.com/sqlalchemy/sqlalchemy
this pointhttps://sqlmodel.tiangolo.com/tutorial/select/
herehttps://github.com/tiangolo/sqlmodel/blob/02da85c9ec39b0ebb7ff91de3045e0aea28dc998/sqlmodel/sql/sqltypes.py#L52
UUID().hexhttps://docs.python.org/3/library/uuid.html#uuid.UUID.hex
integer stringification apprachhttps://docs.sqlalchemy.org/en/14/core/custom_types.html?highlight=guid#backend-agnostic-guid-type
andrewbolsterhttps://github.com/andrewbolster
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
on Aug 26, 2021https://github.com/fastapi/sqlmodel/issues/25#event-5210716763
andrewbolsterhttps://github.com/andrewbolster
on Aug 26, 2021https://github.com/fastapi/sqlmodel/issues/25#event-5210727052
Update GUID handling use stdlib UUID.hexhttps://github.com/andrewbolster/sqlmodel/commit/959f3802187de63cced7a68c21cccbb174379795
https://docs.github.com/articles/closing-issues-via-commit-messages
959f380https://github.com/andrewbolster/sqlmodel/commit/959f3802187de63cced7a68c21cccbb174379795
https://github.com/alucarddelta
alucarddeltahttps://github.com/alucarddelta
on Sep 1, 2021https://github.com/fastapi/sqlmodel/issues/25#issuecomment-909928949
https://github.com/dit7ya
dit7yahttps://github.com/dit7ya
on Sep 27, 2021https://github.com/fastapi/sqlmodel/issues/25#issuecomment-927542936
dit7yahttps://github.com/dit7ya
on Sep 27, 2021https://github.com/fastapi/sqlmodel/issues/25#event-5363011408
Use a fork of SQLModelhttps://github.com/dit7ya/roamex/commit/1f0b70af64e9cad91c3a6f43829a2d77d484204e
1f0b70ahttps://github.com/dit7ya/roamex/commit/1f0b70af64e9cad91c3a6f43829a2d77d484204e
Use a fork of SQLModelhttps://github.com/dit7ya/roamex/commit/ae41cfcd8ff231f5612332f5d1e1344e99fce92c
ae41cfchttps://github.com/dit7ya/roamex/commit/ae41cfcd8ff231f5612332f5d1e1344e99fce92c
https://github.com/chriswhite199
chriswhite199https://github.com/chriswhite199
on Nov 29, 2021https://github.com/fastapi/sqlmodel/issues/25#issuecomment-982039809
https://github.com/frankie567
frankie567https://github.com/frankie567
on Nov 30, 2021https://github.com/fastapi/sqlmodel/issues/25#issuecomment-982355851
@andrewbolsterhttps://github.com/andrewbolster
https://github.com/junekiwi
junekiwihttps://github.com/junekiwi
on Dec 20, 2021https://github.com/fastapi/sqlmodel/issues/25#issuecomment-998321870
SQLAlchemy-Utilshttps://sqlalchemy-utils.readthedocs.io/en/latest/data_types.html#module-sqlalchemy_utils.types.uuid
Ae-Mchttps://github.com/Ae-Mc
on Jan 25, 2022https://github.com/fastapi/sqlmodel/issues/25#event-5949569888
Use my own fork of SQLModel 0.0.6 merged with andrewbolster's forkhttps://github.com/Ae-Mc/climbing-app-backend/commit/f0de4ccf1cba413b5a0136bf6c05db4221547317
f0de4cchttps://github.com/Ae-Mc/climbing-app-backend/commit/f0de4ccf1cba413b5a0136bf6c05db4221547317
https://github.com/mkarbo
mkarbohttps://github.com/mkarbo
on Mar 16, 2022https://github.com/fastapi/sqlmodel/issues/25#issuecomment-1069270351
@tiangolohttps://github.com/tiangolo
leynierhttps://github.com/leynier
on May 28, 2022https://github.com/fastapi/sqlmodel/issues/25#event-6696729052
fix: work around for fastapi/sqlmodel#25https://github.com/leynier/drones/commit/542cf0e7458004431fb8218d228330ef059cf274
fastapi/sqlmodel#25https://github.com/fastapi/sqlmodel/issues/25
542cf0ehttps://github.com/leynier/drones/commit/542cf0e7458004431fb8218d228330ef059cf274
synodriverhttps://github.com/synodriver
on Jun 24, 2022https://github.com/fastapi/sqlmodel/issues/25#event-6872123686
Merge pull request fastapi#25 from leynier/fork-3https://github.com/synodriver/sqlmodel/commit/633b230823bf8ae153ea8ddb15274834a1ad4ab6
fastapi#25https://github.com/fastapi/sqlmodel/issues/25
633b230https://github.com/synodriver/sqlmodel/commit/633b230823bf8ae153ea8ddb15274834a1ad4ab6
tiangolohttps://github.com/tiangolo
completedhttps://github.com/fastapi/sqlmodel/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#26https://github.com/fastapi/sqlmodel/pull/26
on Aug 27, 2022https://github.com/fastapi/sqlmodel/issues/25#event-7272595644
https://github.com/tiangolo
tiangolohttps://github.com/tiangolo
on Aug 27, 2022https://github.com/fastapi/sqlmodel/issues/25#issuecomment-1229280570
#26https://github.com/fastapi/sqlmodel/pull/26
@andrewbolsterhttps://github.com/andrewbolster
tiangolohttps://github.com/tiangolo
bugSomething isn't workinghttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22bug%22
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
on Aug 27, 2022https://github.com/fastapi/sqlmodel/issues/25#event-7272597441
tcompahttps://github.com/tcompa
on Aug 30, 2022https://github.com/fastapi/sqlmodel/issues/25#event-7286912752
Increase sqlmodel version to ^0.0.7https://github.com/fractal-analytics-platform/fractal-client/commit/acb261d4befd09d8d5147ece077a46b90d035481
acb261dhttps://github.com/fractal-analytics-platform/fractal-client/commit/acb261d4befd09d8d5147ece077a46b90d035481
Sign up for freehttps://github.com/signup?return_to=https://github.com/fastapi/sqlmodel/issues/25
Sign in to commenthttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/25
bugSomething isn't workinghttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.