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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:42:38+00:00 2026-05-29T09:42:38+00:00

The manual doesn’t have an example how to use db.allocate_id_range. I tried some code

  • 0

The manual doesn’t have an example how to use db.allocate_id_range. I tried some code and it failed, esxpecially for webapp2:s User model which is an ndb expando model. What I want to do is just create a User entity with an ID number of my choice so I try to use db.allocate_id_range but it is not working:

BadArgumentError: Expected an instance or iterable of (<class 'google.appengine.
ext.db.Model'>, <class 'google.appengine.api.datastore_types.Key'>, <type 'bases
tring'>); received User<address=StringProperty('address'), auth_ids=StringProper
ty('auth_ids', repeated=True), created=DateTimeProperty('created', auto_now_add=
True), firstname=StringProperty('firstname'), lastname=StringProperty('lastname'
), notify=BooleanProperty('notify', default=False), notify_sms=BooleanProperty('
notify_sms', default=False), password=StringProperty('password'), phone_cell=Str
ingProperty('phone_cell'), registered=BooleanProperty('registered', default=Fals
e), sponsor=KeyProperty('sponsor'), updated=DateTimeProperty('updated', auto_now
=True)> (a MetaModel).

The way I try to do it is like this

first_batch = db.allocate_id_range(User, 3001, 3001) #try allocate ID 3001

Am I doing it wrong? I also tried putting the model name in quotes but that didn’t work either. How should I be doing this? Thanks for any advice.

  • 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-29T09:42:39+00:00Added an answer on May 29, 2026 at 9:42 am

    You should be able to use ndb.allocate_ids function to achieve the same functionality.

    If you compare db.allocate_id_range and ndb allocate_ids implementation, you will see that they are both wrapper to the underlying datastore allocate_ids RPC.

    If you want to mimic allocate_id_range with NDB you should be doing something like:

    ctx = tasklets.get_context()
    model.Key('Foo', 1) # the id(1) here is ingnored
    start_id, end_id = ctx.allocate_ids(key, max=3001) # allocate all ids up to 3001
    if start_id <= 3001:
        # it is safe to use 3001
        Foo(id=3001).put()
    

    Or even simpler (like in the doc, guido pointed in the comment):

    start_id, end_id = Foo.allocate_ids(max=3001)
    if start_id <= 3001:
        Foo(id=3001).put()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really like the strtotime() function, but the user manual doesn't give a complete
I really like the PHP function strtotime(), but the user manual doesn't give a
I have used Shibboleth with manual login, meaning the user clicks the login link
Recently I've studied the backpropagation network and have done some manual exercise. After that,
I tried the example in the manual: <delete includeemptydirs=true> <fileset dir=${DIR} includes=**/.svn defaultexcludes=false/> </delete>
In my grid I had following line of code which disabled user's manual resizing:
trying to use this function http://php.net/manual/en/function.strip-tags.php against this: [link-code-html] => <a href=http://www.kqzyfj.com/click-3782261-10563989>invisibleSHIELD for the
Is there an FTP browser hiding away in NetBeans 6.1? The help manual doesn't
What does the following code do? A link to something in the PHP manual
I generally use a manual process: Look at the page, figure out the semantic

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.