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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:20:13+00:00 2026-05-13T09:20:13+00:00

I have a Model UnitPattern, which reference another Model UnitPatternSet e.g. class UnitPattern(db.Model): unit_pattern_set

  • 0

I have a Model UnitPattern, which reference another Model UnitPatternSet

e.g.

class UnitPattern(db.Model):
    unit_pattern_set = db.ReferenceProperty(UnitPatternSet)

in my view I want to display all UnitPatterns having unit_pattern_set refrences as None, but query UnitPattern.all().filter(“unit_pattern_set =”, None) returns nothing, though I have total 5 UnitPatterns, out of which 2 have ‘unit_pattern_set’ set and 3 doesn’t have

e.g.

print 'Total',UnitPattern.all().count()
print 'ref set',UnitPattern.all().filter("unit_pattern_set !=", None).count()
print 'ref not set',UnitPattern.all().filter("unit_pattern_set =", None).count()

outputs:

Total 5
ref set 2
ref not set 0

Shouldn’t sum of query 2 and 3 be equal to query 1 ?

Reason seems to be that I added reference property unit_pattern_set later on, and these UnitPattern objects existed before that, but then how can I filter such entities?

  • 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-13T09:20:14+00:00Added an answer on May 13, 2026 at 9:20 am

    This is described succinctly in the docs:

    An index only contains entities that
    have every property referred to by the
    index. If an entity does not have a
    property referred to by an index, the
    entity will not appear in the index,
    and will never be a result for the
    query that uses the index.

    Note that
    the App Engine datastore makes a
    distinction between an entity that
    does not possess a property and an
    entity that possesses the property
    with a null value (None). If you want
    every entity of a kind to be a
    potential result for a query, you can
    use a data model that assigns a
    default value (such as None) to
    properties used by query filters.

    In your case, you have 3 entities that don’t have the unit_pattern_set property set at all (because that property wasn’t defined in the Model at the time those entities were created) – therefore those properties doesn’t exist in the database representation of that entity, therefore that entity does not appear in the index of that property for that kind of entity.

    Dan Sanderson’s book Programming Google App Engine explains this in great detail on ~page 150 (unfortunately not available in the Google Books preview)

    To fix the models you already have, you’ll have to iterate over a query on UnitPattern (I’ve not tested the following code, please check it before you run it on your live data):

    patterns = UnitPattern.all()
    for pattern in patterns:
      if not pattern.unit_pattern_set:
        pattern.unit_pattern_set = None
        pattern.put()
    

    Edit: Also, the Updating you model’s schema article discuss strategies you can use to handle schema changes such as this in future. However, that article is quite old and its method requires a web browser to keep hitting a url to trigger the next job to update more records – now that Task Queues exist, you could use a series of Tasks to make the change. The article on using deferred.defer has a framework you could utilise – it does a small amount of work, catches the DeadlineExceededError, and uses the handler to queue a new task which picks up where the current task left off.

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

Sidebar

Ask A Question

Stats

  • Questions 397k
  • Answers 397k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT m.amount FROM measurement m, to_date('Dec 01 1900', 'Mon DD… May 15, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer We still have been unable to find a good collection… May 15, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer Well, you keep the ReportDocument in session and bind it… May 15, 2026 at 3:20 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.