1

I have an Event table with fields:

class Event(db.Model):
    """
    Event Model
    """

    account = db.UserProperty(required=True)
    event_id = db.StringProperty(required=True)

Here is the delete function:

@staticmethod
def delete(account,
           event_id):
    """Delete Event by event_id
    Args:
        account     - account
        event_id    - event_id
    Raises:
        None
    """
    if account is not None and event_id is not None:
        event = Event.find_by_account_and_event_id(account, event_id)

        # if a valid event
        if event is not None:
            logging.info('DELETING event with event_id = ' + event.event_id + ' account= ' + str(event.account))
            event.delete()

I see the following error:

2016-06-15 15:45:45.180 DELETING event with event_id = 2a5e5422-dec5-4e87-a462-e2551e3f3cf8 account= test.user
E 2016-06-15 15:45:45.186 delete() takes exactly 2 arguments (0 given)

FYI: This is from app.yaml:

version: 1
runtime: python27
threadsafe: true
api_version: 1

I am not sure what's wrong here. Any thoughts?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
ssk
  • 9,045
  • 26
  • 96
  • 169
  • 1
    do you by any chance overriding the delete method ? – marcadian Jun 16 '16 at 00:50
  • @marcadian I am deriving from db.Model and I am not overriding the delete function. – ssk Jun 16 '16 at 02:30
  • Try `event.key.delete()` instead of `event.delete()` in your last line ([as per docs](https://cloud.google.com/appengine/docs/python/ndb/creating-entities#Python_Deleting_entities))... – Mihail Russu Jun 16 '16 at 14:37
  • @MihailRussu event.key.delete() is for the newer API i.e., ndb.Model. I am still using db.Model. – ssk Jun 16 '16 at 16:59
  • I'm pretty sure you do, because the delete from db does not have any param. May not be override but you're not calling the delete in the db.Model class In [51]: class X(db.Model): ....: pass ....: In [52]: x = X() In [53]: x.put() Out[53]: datastore_types.Key.from_path(u'X', 6052396701319168L, _app=u's~') In [54]: x.delete() – marcadian Jun 16 '16 at 19:00
  • @marcadian, yes you are right. I have a staticmethod in that class. I didn't know that in Python static methods could override the class the method. http://stackoverflow.com/questions/20533349/python-regular-method-and-static-method-with-same-name I renamed my staticmethod and it works fine. If you post your comment as an answer, I can accept it. – ssk Jun 16 '16 at 22:14
  • @ssk ah yeah, you can do that in python :P – marcadian Jun 17 '16 at 00:54

1 Answers1

1

I'm pretty sure you override the delete method, because the delete from db does not have any param. May not be override but you're not calling the delete in the db.Model class

In [51]: class X(db.Model):
             pass 
In [52]: x = X() 
In [53]: x.put() 
Out[53]: datastore_types.Key.from_path(u'X', 6052396701319168L, _app=u's~<removed>') 
In [54]: x.delete() 
marcadian
  • 2,608
  • 13
  • 20