Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Datebug ProtoRPC fatal #150

Open
zrothberg opened this issue Mar 14, 2017 · 2 comments
Open

Datebug ProtoRPC fatal #150

zrothberg opened this issue Mar 14, 2017 · 2 comments

Comments

@zrothberg
Copy link

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
Copy link
Contributor

dhermes commented Mar 15, 2017

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

@zrothberg
Copy link
Author

zrothberg commented Mar 15, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants