Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:59:39+00:00 2026-06-08T19:59:39+00:00

I’ve just finished setting up the foundations for performing schema upgrades on GAE’s datastore

  • 0

I’ve just finished setting up the foundations for performing schema upgrades on GAE’s datastore using mapreduce. We’re using NDB and many or our models utilise the auto_now keyword option to DateTimeProperty to set a last_modified attribute.

last_modified = ndb.DateTimeProperty( auto_now=True )

Of course, on running the mapreduce job which updates entities the last_modified attribute is updated as well which is not really what we want.

def upgrade_entity(entity):
    # modify entity
    yield op.db.Put(entity)

According to the docs you can override the value for a property with auto_now_add set, but not with auto_now.

I’m now thinking there may well be other circumstances where we don’t want the last_modified attribute to be updated as well.

So, is there any way to preserve the entity’s last_modified value or do we add another property or replace these properties with one’s we can control and just set the values manually?


ok, so the consensus seems to be that I should be able to define an alternate version of the model which is only used by the mapreduce code, not the user facing code (I very much want to avoid having to shut down the site to do a schema upgrade) but I haven’t been able to get this to work.

With the following setup the user facing code works properly (updates last_modifed) until I run mapreduce which also works properly (doesn’t update last_modified). After running mapreduce the user facing code no longer updates last_modified..

models.py

class MyModel(ndb.Model):
    # model used by user facing code
    last_modified = ndb.DateTimeProperty( auto_now=True )

upgrade.py

class MyTmpModel(ndb.Model):
    # model used by mapreduce code
    @classmethod
    def _get_kind(cls):
        return 'MyModel'
    last_modified = ndb.DateTimeProperty( auto_now=False )

def upgrade_model(entity):
    # mapper function 
    # modify entity
    yield op.db.Put(entity)     

mapreduce.yaml

mapreduce:
- name: Upgrade Model
  mapper:
    input_reader: mapreduce.input_readers.DatastoreInputReader
    handler: upgrade.upgrade_model
    params:
    - name: entity_kind
      default: upgrade.MyTmpModel

ok, I’m going put my issues here down to the fact that I have been testing this in dev_server and the differences in the way things run there compared to the real gae server. I’ve concluded that in dev_server all the code is running in the same process and the different model versions are not getting along.. from the NDB model docs:

An application should not define two model classes with the same kind, even if they live in different modules. An application’s kinds are considered a global “namespace”.

I’ll assume that I can rely on the fact that on the real gae server the mapreduce code will run in separate instances and these version clashes will not occur and it will not affect the user facing server instances so the setup above should work as expected.

Thanks Tim & Guido for your help.

cheers,

J

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:59:42+00:00Added an answer on June 8, 2026 at 7:59 pm

    The solution is to set auto_now=False in all your model definitions in the map/reduce code.

    My suggestion for doing this with the least chance for errors:

    Define a global constant that can be True or False which you use for all the auto_now settings in your model definitions. Then you have to change only that one line to change it from True to False for all models. You can even make it compute the value automatically based on some environment variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.