Search code examples
pythongoogle-app-enginebulkloader

How to upload date with bulkloader?


I have the following code in bulkloader.yaml:

  - property: dismissal_date
    external_name: dismissal_date
    import_transform: "lambda x: None if x is None or x=='' else datetime.datetime.strptime(x, '%d.%m.%Y').date()"

models.py:

class Employee(ndb.Model):
    dismissal_date = ndb.DateTimeProperty()

and upload file (csv):

last_name,first_name,middle_name,region,dismissal_date
Last name,First name,Middle name,22,13.01.2009

But I am getting the following error:

BadValueError: Unsupported type for property dismissal_date: <type 'datetime.date'>

Solution

  • The following actually works (which is strange since the doc says that I should use .date()):

    import_transform: "lambda x: None if x is None or x=='' else datetime.datetime.strptime(x, '%d.%m.%Y')"
    

    Source of transform.py helped to identify that.

    I've change property type to DateProperty(), but still date saved with time component (00:00:00).