1
votes

I know the difference between DateProperty and DateTimeProperty

difference between DateProperty and DateTimeProperty

I also appreciate how I could maintain my Schema (particularly missing values for properties) with tasks

https://stackoverflow.com/a/2019882/1175496

But I have a Model with date_filed=db.DateProperty I find I almost always want the (time) accuracy of db.DateTimeProperty How can I convert this field from DateTime to DateTimeProperty?

My questions are:

  • How to do it
    • ie simply change from date_filed=db.DateProperty to date_filed=db.DateTimeProperty
  • Will it somehow update existing entities automatically?
    • ie or must I create a task to change them?
  • If entities with have different types for same properties, how does filtering and ordering on that property work?
    • ie DateProperty to a datetime.datetime value
    • ie

When a query involves a property with values of mixed types, the Datastore uses a deterministic ordering based on the internal representations: ...

  1. Fixed-point numbers
    • Integers
    • Dates and times
  • What are some outcomes / pitfalls
    • ie Validation Errors
1

1 Answers

3
votes

I experimented with the simplest option, anticipated in the question. Also anticipated by the db.Model designers, it would seem (i.e. easy to do!)

  • How to do it
    • Yes: simply change from date_filed=db.DateProperty to date_filed=db.DateTimeProperty
  • Will it somehow update existing entities automatically?
    • Kind of: Specifically DateProperty.get_value_for_datastore method actually converts any datetime.date object to a datetime.datetime object before storing it as a "raw value" in the database.
    • Existing entities aren't really updated automatically, they just start using DateTimeProperty.make_value_from_datastore, (the opposite of get_value_for_datastore) which falls back to Property.make_value_from_datastore, which returns the raw value; the datetime.datetime object; not "truncating" it to a datetime.date object
    • No need to : ...create a task to change them
  • If entities with have different types for same properties, how does filtering and ordering on that property work?
    • Irrelevant in this case; they have the same underlying type.
    • Although the "deterministic ordering based on internal representations" statement, which lists dates and datetimes both at the same bullet, suggests they have a common internal representation so they're comparable for ordering/filtering, etc.
  • What are some outcomes / pitfalls
    • None encountered in this case; maybe someone has stories of other datatype migrations/conversions?