Skip to content

Commit 58b52b5

Browse files
authored
Fix Int type redefinition error by renaming the scalar type (#1156)
* Fix Int type redefinition error by renaming the scalar type - add unit test for testing the scalar type. * bumpversion to 4.6.1 * Add unit test to check that default graphql int type errors * rename scalar type back to Int and remove Int from graphql reserved types
1 parent de0f1bc commit 58b52b5

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 4.6.0
2+
current_version = 4.6.1
33
commit = False
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(rc(?P<build>\d+))?

orchestrator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
"""This is the orchestrator workflow engine."""
1515

16-
__version__ = "4.6.0"
16+
__version__ = "4.6.1"
1717

1818

1919
from structlog import get_logger

orchestrator/graphql/schema.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@
6363
from orchestrator.graphql.schemas.subscription import SubscriptionInterface
6464
from orchestrator.graphql.schemas.version import VersionType
6565
from orchestrator.graphql.schemas.workflow import Workflow
66-
from orchestrator.graphql.types import SCALAR_OVERRIDES, OrchestratorContext, ScalarOverrideType, StrawberryModelType
66+
from orchestrator.graphql.types import (
67+
SCALAR_OVERRIDES,
68+
OrchestratorContext,
69+
ScalarOverrideType,
70+
StrawberryModelType,
71+
)
6772
from orchestrator.services.process_broadcast_thread import ProcessDataBroadcastThread
6873
from orchestrator.settings import app_settings
6974

orchestrator/graphql/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Any, NewType, TypeVar
1818

1919
import strawberry
20-
from graphql import GraphQLError
20+
from graphql import GraphQLError, GraphQLNamedType
2121
from strawberry.dataloader import DataLoader
2222
from strawberry.experimental.pydantic.conversion_types import StrawberryTypeFromPydantic
2323
from strawberry.scalars import JSON
@@ -122,6 +122,9 @@ class GraphqlFilter:
122122
parse_value=lambda v: v,
123123
)
124124

125+
# TODO: Remove Hack to prevent the error: `Redefinition of reserved type 'Int'`
126+
if hasattr(GraphQLNamedType, "reserved_types"):
127+
GraphQLNamedType.reserved_types.pop("Int", None)
125128
IntType = strawberry.scalar(
126129
NewType("Int", int),
127130
description="An arbitrary precision integer",
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from decimal import Decimal
2+
from typing import Any
3+
4+
import pytest
5+
import strawberry
6+
7+
from orchestrator.graphql.types import SCALAR_OVERRIDES
8+
9+
BIG_INT_VALUE = 2**40 # 1,099,511,627,776
10+
DECIMAL_VALUE = Decimal("1234567890.123456789")
11+
12+
13+
@strawberry.type
14+
class ScalarsTest:
15+
big_int: int
16+
decimal_value: Decimal
17+
18+
19+
@strawberry.type
20+
class Query:
21+
@strawberry.field
22+
def scalars(self) -> ScalarsTest:
23+
"""Return test values for large int and decimal."""
24+
return ScalarsTest(big_int=BIG_INT_VALUE, decimal_value=DECIMAL_VALUE)
25+
26+
27+
schema = strawberry.Schema(query=Query)
28+
schema_with_overrides = strawberry.Schema(query=Query, scalar_overrides=SCALAR_OVERRIDES)
29+
30+
31+
def test_big_int_and_decimal_handling() -> None:
32+
"""Verify that large integers and Decimal values serialize correctly."""
33+
query = """
34+
query {
35+
scalars {
36+
bigInt
37+
decimalValue
38+
}
39+
}
40+
"""
41+
42+
result: Any = schema_with_overrides.execute_sync(query)
43+
assert result.errors is None, f"GraphQL errors occurred: {result.errors}"
44+
45+
data = result.data["scalars"]
46+
47+
assert data["bigInt"] == BIG_INT_VALUE
48+
decimal_serialized = str(data["decimalValue"])
49+
assert decimal_serialized.startswith(str(DECIMAL_VALUE))
50+
51+
52+
@pytest.mark.xfail(reason="Graphql now supports non 32-bit signed integers", strict=False)
53+
def test_big_int_and_decimal_handling_fails_without_scalar_overrides() -> None:
54+
"""Verify that large integers and Decimal values serialize correctly."""
55+
query = """
56+
query {
57+
scalars {
58+
bigInt
59+
decimalValue
60+
}
61+
}
62+
"""
63+
64+
# with pytest.raises(GraphQLError, match="Int cannot represent non 32-bit signed integer"):
65+
result = schema.execute_sync(query)
66+
assert any("Int cannot represent non 32-bit signed integer" in err.message for err in result.errors or [])

0 commit comments

Comments
 (0)