From 9250c3e7a93018551ae454c312bfc1d38b7a3df8 Mon Sep 17 00:00:00 2001 From: Kent Rasmussen Date: Wed, 20 Dec 2023 08:45:53 +0900 Subject: [PATCH] add a clamp for values that can get really high --- model_validators.py | 4 ++++ models.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 model_validators.py diff --git a/model_validators.py b/model_validators.py new file mode 100644 index 00000000..58bcd374 --- /dev/null +++ b/model_validators.py @@ -0,0 +1,4 @@ +import sys + +def clamp64BitInteger(prop, value): + return max(0, min(sys.maxsize, value)) \ No newline at end of file diff --git a/models.py b/models.py index d2f3cdea..c13167bd 100644 --- a/models.py +++ b/models.py @@ -1,5 +1,6 @@ from config import * from functions import * +from model_validators import clamp64BitInteger class User(ndb.Expando): name=ndb.StringProperty() @@ -51,7 +52,7 @@ class Character(ndb.Expando): type=ndb.StringProperty() level=ndb.IntegerProperty(default=1) worth=ndb.IntegerProperty(default=0) #total gold worth - xp=ndb.IntegerProperty(default=0) + xp=ndb.IntegerProperty(default=0, validator=clamp64BitInteger) owner=ndb.StringProperty() referrer=ndb.StringProperty() created=ndb.DateTimeProperty(auto_now_add=True)