1

I have created an Entity, called "Event" in the Google Cloud Datastore for my project. The entity has an ID generated by AppEngine followed by two properties

  • Location
  • Date

I am trying to query this entity by its ID (5629499534213120), so , here is my code.

 key = 5629499534213120
 e = Event.get_by_id(key)
 logging.info("Event Location = %s" % e.Location)

The value of e is NoneType.

code

 __author__ = 'vinayjoseph'
from google.appengine.ext import ndb
import logging
class Event(ndb.Model):
 """Models an individual event at xxx xxxx """
 Date = ndb.DateTimeProperty()
 Location = ndb.StringProperty()
def get_meeting_date():
 """gets the next meeting date from the No SQL Schemaless Google Datastore
 """
 key = 5629499534213120
 e = Event.get_by_id(key)
 logging.info("Event Location = %s" % e.Location)

e is NoneType

In the datastore I see the following at https://console.developers.google.com/project/apps~xxxxx/datastore/editentity?key=xxxxx%2FEvent%20id:5629499534213120

screen shot of the entity in the datastore

I suspect the problem might be with my key.

When I try to query the datastore in development using dev_appserver.py it works. I am using a different key for dev.

def get_meeting_date():
 """gets the next meeting date from the No SQL Schemaless Google Datastore
 """
 #dev
 key = 6401356696911872
 #prd
 #key = 5629499534213120
 e = Event.get_by_id(key)
 logging.info("Event Location = %s" % e.Location)

enter image description here

asked Sep 2, 2014 at 13:39
3
  • Try adding quotes around the ID event_key = ndb.Key("Event", "5629499534213120") Commented Sep 2, 2014 at 13:52
  • ID should be int int, so that should be fine. Does this entity have a parent entity? Commented Sep 2, 2014 at 18:54
  • Tried both and it did not work And no it does not have a parent entity Commented Sep 2, 2014 at 21:19

2 Answers 2

2

OK so I finally figured it out.

I had to make a few changes to the entity itself, just to get the filtering right. So the new properties are as seen below. Entity Properties

The code in python is as follows:

__author__ = 'vinayjoseph'
from google.appengine.ext import ndb
import logging
from datetime import datetime
class Event(ndb.Model):
 """Models an individual event at xxx xxx """
 Date = ndb.DateTimeProperty()
 Location = ndb.StringProperty()
 Address = ndb.StringProperty()
 Name = ndb.StringProperty()
def get_meeting_date():
 """gets the next meeting date from the No SQL Schemaless Google Datastore
 """
 qry = Event.query(Event.Name == 'Next Meeting Location')
 for event in qry.fetch(1):
 logging.info("Meeting is on %s at %s" % (str(event.Date), event.Address))

And it works like a charm. Check out the log entry in app-engine

enter image description here

answered Sep 5, 2014 at 12:34
Sign up to request clarification or add additional context in comments.

Comments

0

In the query method, you're using ancestor. If your entities have a parent, then you have to include it in the get_by_id call.

answered Sep 3, 2014 at 6:37

1 Comment

Yes, however I am not using this method anymore. The event var is of type NoneType in the get_meeting_date() method.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.