GoogleCloudPlatform / endpoints-proto-datastore

Apache License 2.0
154 stars 52 forks source link

Datebug ProtoRPC fatal #150

Open zrothberg opened 7 years ago

zrothberg commented 7 years ago

So some funny things happen if you insert a date property before 1900. NDB half lets you put the value in the database but ProtoRPC will not return it from the database. Which leads to some weird behavior.

class Patient(EndpointsModel):

name = ndb.StringProperty()
user = EndpointsUserProperty(required=True, raise_unauthorized=True)
date_of_birth = ndb.DateProperty()
age = ndb.IntegerProperty() 

def calculate_age(self):
    today = date.today()
    birthday = self.date_of_birth
    self.age = today.year - birthday.year - ((today.month, today.day) < (birthday.month , birthday.day))

def _pre_put_hook(self):
    if self.date_of_birth:
        self.calculate_age()

@endpoints.api(name='patient', version='vGDL', description='API for patient') class PatientApi(remote.Service):

@Patient.method(
                request_fields=('name','date_of_birth'),
                name = 'patient.insert',
                path = 'patient',
                http_method = 'POST')
def insert_patient(self,patient):
    patient.put()
    return patient

@Patient.query_method(user_required=True,
                      query_fields=['name'],
                      name='patient.list',
                      path= 'patient')
def list_patient(self,query):
    return query

First it throws a 503 when storing a value before hand image but it succeeded at putting it image Second is it looks up all queries that contain this entity image The only solution when this happens seems to be deleting the entity. Its simple enough to work around by raising a bad request exception. It just seems tedious to do everytime I add a date.

dhermes commented 7 years ago

Thanks for the report @zrothberg. Any stacktrace in your logs?

zrothberg commented 7 years ago

This is one I snuck by it. https://gist.github.com/zrothberg/8cb79269c525f309ba72f3238e82c2d1

This one is the one I was reffering too in the post https://gist.github.com/zrothberg/5088984543ad182afddfd6ea7b2d4ded

(I don't know how to imbed gists)

here are some other values I managed to add anything before 1900 in the year would not come back out. The issue only seems to affect years. Also Datastore has a pretty robust knowledge of leap years. image