Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decimal type conversion #376

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def convert_variant_to_impl_type(
)


@convert_sqlalchemy_type.register(column_type_eq(sqa_types.DECIMAL))
@convert_sqlalchemy_type.register(column_type_eq(Decimal))
def convert_sqlalchemy_hybrid_property_type_decimal(type_arg: Any, **kwargs):
# The reason Decimal should be serialized as a String is because this is a
Expand Down
2 changes: 2 additions & 0 deletions graphene_sqlalchemy/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import List, Optional

from sqlalchemy import (
DECIMAL,
Column,
Date,
Enum,
Expand Down Expand Up @@ -184,6 +185,7 @@ class ShoppingCart(Base):
__tablename__ = "shopping_carts"

id = Column(Integer(), primary_key=True)
dec = Column(DECIMAL())

# Standard Library types

Expand Down
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def use_legacy_many_relationships():
set_non_null_many_relationships(True)



def test_hybrid_prop_int():
@hybrid_property
def prop_method() -> int:
Expand Down Expand Up @@ -795,6 +794,7 @@ class Meta:

shopping_cart_expected_types: Dict[str, Union[graphene.Scalar, Structure]] = {
# Basic types
"dec": graphene.String,
"hybrid_prop_str": graphene.String,
"hybrid_prop_int": graphene.Int,
"hybrid_prop_float": graphene.Float,
Expand Down