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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:26:13+00:00 2026-06-05T01:26:13+00:00

I’m trying to test an application that runs on App Engine. I’m using the

  • 0

I’m trying to test an application that runs on App Engine. I’m using the Testbed framework, and so far it works like a charm, except for the following unexpected behaviour:

A test like this would work just fine (simplified version without a framework):

from google.appengine.ext import db, testbed
testbed = testbed.Testbed()
testbed.activate()
testbed.init_datastore_v3_stub()
class Foo(db.Model):
    pass

# now for the tests:
key = Foo().put()
assert key == db.Key.from_path('Foo', key.id())
assert Foo.all(keys_only=True).get() == db.Key.from_path('Foo', key.id())
assert db.get(db.Key.from_path('Foo', key.id()))  # fails!

testbed.deactivate()

However, the following would fail (again, simplified version):

from google.appengine.ext import db, testbed
testbed = testbed.Testbed()
testbed.activate()
testbed.init_datastore_v3_stub()
from myapp.models import Foo

# now for the tests:
key = Foo().put()
assert key == db.Key.from_path('Foo', key.id())  # fails!
assert Foo.all(keys_only=True).get() == db.Key.from_path('Foo', key.id())  # fails!
assert db.get(db.Key.from_path('Foo', key.id()))  # fails!

# however, the following will succeed:
assert key == db.Key.from_path('Model', key.id())
assert Foo.all(keys_only=True).get() == db.Key.from_path('Model', key.id()) 
assert db.get(key)

testbed.deactivate()

Where does the model name disappear during the tests? And how come it only happens with imported modules?

EDIT:

Thanks proppy, typos fixed.

Nick Johnson, let me try to explain it better.

When I query a result from the testbed datastore stub, I get an entity, just like I’d expect. But when I call the .key() method on that entity, I get things like datastore_types.Key.from_path(u'Model', 1L, _app=u'testbed-test'), while Model is clearly not the correct kind of my entity.

When I try to get the entity for that key (datastore_types.Key.from_path(u'Model', 1L, _app=u'testbed-test')), it works just fine.

The problem is, when I only know the id of a datastore entity, and I try to construct the key manually, using db.Key.from_path(...).

For example, the kind should be User, so I can construct the key using db.Key.from_path('User', 1). But I cannot get an entity from the datastore using that key. I can, however, using db.Key.from_path('Model', 1), but, as I said, Model is not the correct datastore kind.

In other words:

from myapp.models import User
User(email='dont@write.us').kind()  # returns 'Model', not 'User'!

Note that this unexpected behaviour does not occur in production or in the dev server, only when using testbed, and only when the db.Model subclass is defined in my application code (i.e. not in the test cases themselves).

I am not using Django, I’m using Pyramid with traversal, but the unit tests I’m running here do not call any framework-specific code.

Note that I haven’t tried this with ndb yet the same thing happens with ndb as well..

Edit 2:

Apparently I haven’t noticed that all of my classes were subclasses of a google.appengine.ext.db.polymodel.PolyModel subclass, so the keys were in fact correctly set as Model, because the kind is Model on all PolyModel subclasses.

  • 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-05T01:26:14+00:00Added an answer on June 5, 2026 at 1:26 am

    To answer my own question, this problem was caused by a file called migrations.py that I had in my project, which redefined my models using classes that had different properties. When I was running the tests, nose tried to import all available files to post coverage results, which caused the module definition clash, and thus all the confusion.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.