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

  • Home
  • SEARCH
  • 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 633655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:12:36+00:00 2026-05-13T20:12:36+00:00

Here is some code that is not working how it is supposed to work.

  • 0

Here is some code that is not working how it is supposed to work. Every time the database is queried, I get either a 0 or 1 value for the options, and the values in database do not increment, even though as as you can see, in line 86 and 89, the values are being incremented. Any idea what’s going wrong here? I am using Django on Google App engine.

        user_result = request.POST['json']
 65     user_result = json.loads(user_result)
 66     user_country = get_user_country(user_result)
 67     question_number = get_question_number(user_result)
 68     answered_option = get_answered_option(user_result)
 69 
 70     country_option_1 = 0
 71     country_option_2 = 0
 72     world_option_1 = 0
 73     world_option_2 = 0
 74 
 75     """
 76     Get already existing record for the question for the contry, or create
 77     new one and put/update in db
 78     """
 79 
 80     country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number)
 81     flag = False
 82     for i in country_wide_data:
 83         flag = True
 84     if flag:
 85         if answered_option==1:
 86             country_wide_data[0].optionOne = country_wide_data[0].optionOne + 1
 87 
 88         elif answered_option==2:
 89             country_wide_data[0].optionTwo = country_wide_data[0].optionTwo + 1
 90         country_option_1 = country_wide_data[0].optionOne
 91         country_option_2 = country_wide_data[0].optionTwo
 92         country_wide_data[0].put()
 93     else:
 94         country_wide_data = CountryWideData(country=user_country, questionNo=question_number)
 95 
 96         if answered_option==1:
 97             country_wide_data.optionOne = 1
 98             country_wide_data.optionTwo = 0
 99         elif answered_option==2:
100             country_wide_data.optionOne = 0
101             country_wide_data.optionTwo = 1
102         country_option_1 = country_wide_data.optionOne
103         country_option_2 = country_wide_data.optionTwo
104         country_wide_data.put()
  • 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-13T20:12:36+00:00Added an answer on May 13, 2026 at 8:12 pm

    You are never using fetch() to actually execute the GqlQuery that you create in line 80.

    Try this:

    country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number).fetch()
    

    By the way, you are going to want to do this incrementing inside of a transaction; otherwise, you will get a race condition if more than one request can execute this code, and the counts will be inaccurate. The documentation on transactions is here: http://code.google.com/appengine/docs/python/datastore/transactions.html

    Generally, you are going to want to take the code that creates or updates these entities and put them into functions, like this:

    def increment_existing_data(key, answered):
        cwd_to_incr = db.get(key)
        if answered == 1:
            cwd_to_incr.optionOne += 1
        elif answered == 2:
            cwd_to_incr.optionTwo += 1
        cwd_to_incr.put()
    
    def create_new_data(answered, user_country, question_number):
        new_data = CountryWideData(country=user_country, questionNo=question_number)
        if answered == 1:
            new_data.optionOne = 1
            new_data.optionTwo = 0
        elif answered == 2:
            new_data.optionOne = 0
            new_data.optionTwo = 1
        new_data.put()
    

    Then, you can call these functions using the db.run_in_transacation method, like this:

    country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number).get()
    if country_wide_data is not None:
        db.run_in_transaction(increment_existing_data, country_wide_data.key(), answered_option)
    else:
        db.run_in_transaction(create_new_data, answered_option,  user_country, question_number)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on some code involving pipes. The idea is that I'm supposed to
I have some code here that uses bitsets to store many 1 bit values
I've got some code here that works great on IPv4 machines, but on our
I have some code that is using SyncEnumerator. As you can see here ,
So I have some PHP code that looks like: $message = 'Here is the
Here's some example code: class Obj attr :c, true def == that p '=='
Just some example code here, but I have lists of strings that I want
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
Why does the titlebar overlap the pixels of JPanel. Here some code: protected void
Here's some code (full program follows later in the question): template <typename T> T

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.