File tree 3 files changed +9
-5
lines changed
3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
from ...db import db
4
4
from ...enums import BoxState as BoxStateEnum
5
- from ..fields import UIntForeignKeyField
5
+ from ..fields import UIntForeignKeyField , ZeroDateTimeField
6
6
from .box_state import BoxState
7
7
from .distribution_event import DistributionEvent
8
8
from .location import Location
@@ -44,7 +44,7 @@ class Box(db.Model): # type: ignore
44
44
on_delete = "SET NULL" ,
45
45
on_update = "CASCADE" ,
46
46
)
47
- deleted_on = DateTimeField (column_name = "deleted" , null = True , default = None )
47
+ deleted_on = ZeroDateTimeField (column_name = "deleted" , null = True , default = None )
48
48
distribution_event = UIntForeignKeyField (
49
49
column_name = "distro_event_id" ,
50
50
field = "id" ,
Original file line number Diff line number Diff line change @@ -77,7 +77,11 @@ class UIntForeignKeyField(ForeignKeyField):
77
77
78
78
79
79
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
+ """
81
85
82
86
def adapt (self , value ):
83
87
if value == "0000-00-00 00:00:00" :
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ def _assert_successful_request(*args, **kwargs):
20
20
queried_box = _assert_successful_request (auth0_client , query )["box" ]
21
21
assert queried_box == {"id" : "100000000" }
22
22
23
- query = """ query { box(labelIdentifier: "328765") { state size { id } } }"""
23
+ query = ' query { box(labelIdentifier: "328765") { deletedOn state size { id } } }'
24
24
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 }
26
26
27
27
query = """query { beneficiary(id: 100000001) { dateOfBirth } }"""
28
28
queried_beneficiary = _assert_successful_request (auth0_client , query )
You can’t perform that action at this time.
0 commit comments