Skip to content

Commit 8f1e254

Browse files
committed
Declare Box.deleted_on as ZeroDateTimeField
1 parent 7bd83ee commit 8f1e254

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

back/boxtribute_server/models/definitions/box.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ...db import db
44
from ...enums import BoxState as BoxStateEnum
5-
from ..fields import UIntForeignKeyField
5+
from ..fields import UIntForeignKeyField, ZeroDateTimeField
66
from .box_state import BoxState
77
from .distribution_event import DistributionEvent
88
from .location import Location
@@ -44,7 +44,7 @@ class Box(db.Model): # type: ignore
4444
on_delete="SET NULL",
4545
on_update="CASCADE",
4646
)
47-
deleted_on = DateTimeField(column_name="deleted", null=True, default=None)
47+
deleted_on = ZeroDateTimeField(column_name="deleted", null=True, default=None)
4848
distribution_event = UIntForeignKeyField(
4949
column_name="distro_event_id",
5050
field="id",

back/boxtribute_server/models/fields.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ class UIntForeignKeyField(ForeignKeyField):
7777

7878

7979
class ZeroDateTimeField(DateTimeField):
80-
"""Custom class to convert MySQL zero DATETIME field value into None."""
80+
"""Custom class to convert MySQL zero DATETIME field value into None.
81+
If this is not used, peewee will return the zero datetime as string, and the
82+
conversion in `graph_ql.scalars` will fail with the message 'GraphQLError:
83+
str.replace() takes no keyword arguments'.
84+
"""
8185

8286
def adapt(self, value):
8387
if value == "0000-00-00 00:00:00":

back/test/integration_tests/test_operations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def _assert_successful_request(*args, **kwargs):
2020
queried_box = _assert_successful_request(auth0_client, query)["box"]
2121
assert queried_box == {"id": "100000000"}
2222

23-
query = """query { box(labelIdentifier: "328765") { state size { id } } }"""
23+
query = 'query { box(labelIdentifier: "328765") { deletedOn state size { id } } }'
2424
queried_box = _assert_successful_request(auth0_client, query)
25-
assert queried_box == {"state": "Donated", "size": {"id": "68"}}
25+
assert queried_box == {"state": "Donated", "size": {"id": "68"}, "deletedOn": None}
2626

2727
query = """query { beneficiary(id: 100000001) { dateOfBirth } }"""
2828
queried_beneficiary = _assert_successful_request(auth0_client, query)

0 commit comments

Comments
 (0)