From 6b036aca8a575491928e6436baef773059756bae Mon Sep 17 00:00:00 2001 From: Jendrik Date: Fri, 13 Jan 2023 17:23:02 +0100 Subject: [PATCH] fix(decimal columns): register DECIMAL type for conversion as well, add it to the test --- graphene_sqlalchemy/converter.py | 1 + graphene_sqlalchemy/tests/models.py | 2 ++ graphene_sqlalchemy/tests/test_converter.py | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/converter.py b/graphene_sqlalchemy/converter.py index 26f5b3a..dc7e2cd 100644 --- a/graphene_sqlalchemy/converter.py +++ b/graphene_sqlalchemy/converter.py @@ -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 diff --git a/graphene_sqlalchemy/tests/models.py b/graphene_sqlalchemy/tests/models.py index 9531aaa..c36e0a9 100644 --- a/graphene_sqlalchemy/tests/models.py +++ b/graphene_sqlalchemy/tests/models.py @@ -7,6 +7,7 @@ from typing import List, Optional from sqlalchemy import ( + DECIMAL, Column, Date, Enum, @@ -184,6 +185,7 @@ class ShoppingCart(Base): __tablename__ = "shopping_carts" id = Column(Integer(), primary_key=True) + dec = Column(DECIMAL()) # Standard Library types diff --git a/graphene_sqlalchemy/tests/test_converter.py b/graphene_sqlalchemy/tests/test_converter.py index b4c6eb2..fa2c7bd 100644 --- a/graphene_sqlalchemy/tests/test_converter.py +++ b/graphene_sqlalchemy/tests/test_converter.py @@ -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: @@ -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,