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

Add support for Decimal in Pydantic and SQLAlchemy · Issue #30 · fastapi/sqlmodel · GitHub

Repository navigation

Add support for Decimal in Pydantic and SQLAlchemy #30

Closed

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 SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

class City(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)  # pylint: disable=invalid-name
    name: str = Field(nullable=False, max_length=150, index=False)
    population: Optional[int] = Field(default=None, index=False)
    latitude: condecimal(max_digits=13, decimal_places=10) = Field(nullable=False, index=False)
    longitude: condecimal(max_digits=13, decimal_places=10) = Field(nullable=False, index=False)

Description

When setting max_digits and decimal_places to condecimal these are ignored.
The SQL CREATE TABLE resulting from the previous model city definition results in:

CREATE TABLE city (
	id INTEGER AUTO_INCREMENT, 
	name VARCHAR(150) NOT NULL, 
	population INTEGER, 
	latitude NUMERIC NOT NULL, 
	longitude NUMERIC NOT NULL, 
	PRIMARY KEY (id)
)

So latitude and longitude are created with default parameters max_digits = 10 and decimal_places = 0.

Operating System

Linux

Operating System Details

Ubuntu 18.04

SQLModel Version

0.0.4

Python Version

3.7.11

Additional Context

This is my requirements.txt:

fastapi==0.68.1
uvicorn==0.15.0
python-multipart==0.0.5
pydantic==1.8.2
pymysql==1.0.2
python-jose[cryptography]
passlib
starlette-json
bcrypt
sqlmodel==0.0.4

Activity

  1. robcxyz commented on Sep 19, 2021

    Contributor

    I submitted a PR #103 to address this. Pydantic arguments needed to be mapped to sqlalchemy's for that type.

  2. added
    featureNew feature or request
    and removed
    questionFurther information is requested
    on Dec 13, 2021
  3. changed the title [-]Set max_digits and decimal_places in condecimal are ignored[/-] [+]Add support for Decimal in Pydantic and SQLAlchemy[/+] on Dec 13, 2021
  4. tiangolo commented on Dec 13, 2021

    Member

    Thanks for the feedback @roomm! 🤓

    This was added in @robcxyz's PR #103, it is now included in the (just released) SQLModel 0.0.5 🎉

  5. github-actions commented on Dec 24, 2021

    Contributor

    Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL