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 7510601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:16:13+00:00 2026-05-29T23:16:13+00:00

Recently there’s been some data structure changes in our app, and we decided to

  • 0

Recently there’s been some data structure changes in our app, and we decided to use namespaces to separate different versions of of the data, and a mapreduce task that converts old entities to the new format.

Now that’s all fine, but we don’t want to always isolate the entire data set we have. The biggest part of our data is stored in a kind that’s pretty simple and doesn’t need to change often. So we decided to use per-kind namespaces.

Something like:

class Author(ndb.model.Model):
    ns = '2'

class Book(ndb.model.Model):
    ns = '1'

So, when migrating to version 2, we don’t need to convert all our data (and copy all ‘Book’ kinds to the other namespace), only entities of the ‘Author’ kind. Then, instead of defining the appengine_config.namespace_manager_default_namespace_for_request, we just the ‘namespace’ keyword arguments to our queries:

Author.query(namespace=Author.ns).get()

Question: how to store (i.e. put()) the different kinds using these different namespaces? Something like:

# Not an API
Author().put(namespace=Author.ns)

Of course, the above doesn’t work. (Yes, I could ask the datastore for an avaliable key in that namespace, and then use that key to store the instance with, but it’s an extra API call that I’d like to avoid.)

  • 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-05-29T23:16:15+00:00Added an answer on May 29, 2026 at 11:16 pm

    A Model instance will use the namespace you set with the namespace_manager[1] as you can see here: python/google/appengine/ext/db/init.py

    What you could do is create a child class of Model which expects a class-level ‘ns’ attribute to be defined. This sub class then overrides put() and sets the namespace before calling original put and resets the namespace afterwards. Something like this:

    '''
    class MyModel(db.Model):
    
        ns = None
    
        def put(*args, **kwargs):
            if self.ns == None:
                raise ValueError('"ns" is not defined for this class.')
            original_namespace = namespace_manager.get_namespace()
            try:
                super(MyModelClass, self).put(*args, **kwargs)
            finally:
                namespace_manager.set_namespace(original_namespace)
    '''
    

    [1] http://code.google.com/appengine/docs/python/multitenancy/multitenancy.html

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

Sidebar

Related Questions

Recently there has been quite some hype around all the different mocking frameworks in
recently I just started to use python3 and realised that there alot of changes
In some code I saw recently there was a structure defined like this: typedef
I've been doing some reading about continuous integration recently and there is a scenario
Recently there have been a couple questions regarding static type constraints and inline: Use
Recently there has been a lot of hype about URL Shortening. I guess some
I've been working with pthreads a fair bit recently and there's one little thing
Been on a huge learning binge with ASP.MVC 2 lately, and recently uncovered there
There have been several questions recently about database indexing and clustered indexing and it
Is there any free hosting for Javascript? Recently google has been hosting jQuery,etc... and

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.