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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:46:56+00:00 2026-06-17T09:46:56+00:00

I have this two models: Tutorial and Chapter. Chapters have a key reference to

  • 0

I have this two models: Tutorial and Chapter. Chapters have a key reference to the tutorial they belong. Now I’m trying to list all the chapter that belong to a specific Tutorial but I can’t get the query to work:

class TutView(FuHandler):
    def get(self):
        tutKey = self.request.get('tut_key')
        tut = db.Key.from_path('Tutorial', tutKey)
        chaps = db.GqlQuery("SELECT * FROM Chapter " +
                            "WHERE __key__ = KEY('Tutorial', :1)", tut)
        self.render('tutView.html', chaps=chaps)

When running I get this error:

BadArgumentError: Expected an integer id or string name as argument 2; 
received datastore_types.Key.from_path(u'Tutorial', u'<bound method 
Tutorial.key of <main.Tutorial object at 0x00.............

Chapter model:

class Chapter(db.Model):
    tutorial = db.ReferenceProperty(Tutorial, collection_name='chapters')
    title = db.StringProperty(required=True)
    content = db.TextProperty(required=True)

Tutorial model:

class Tutorial(db.Model):
    title = db.StringProperty(required=True)
    presentation = db.TextProperty(required=True)

update:
i managed to get no errors but i get no results (so, probably it’s wrong):

chaps = db.GqlQuery("SELECT * FROM Chapter " + 
                    "WHERE __key__ = KEY('tutorial', :1)", str(tutKey))

update2:
The problem might be on the way i store or retrieve the tutKey. I’m getting the key with the URL… and and that’s probably not working… but i don’t know other way

  • 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-17T09:46:57+00:00Added an answer on June 17, 2026 at 9:46 am

    The KEY() GQL function is used to create Keys based on two parameters: The Entity, and the name/id.
    If you look at your code, you will see that you are passing it a db.Key object as a parameter.
    Hence, the error message:

    Expected an integer id or string name as argument 2; 
    received datastore_types.Key.from_path(u'Tutorial', ...)
    

    Also, you need to test against the tutorial property of the Chapter entity, and not against its own __key__.

    I do not work with GQL, I use the Query objects instead. You provide them with the db.Key object directly, so I assume this should work:

    chaps = db.GqlQuery("SELECT * FROM Chapter " +
                            "WHERE tutorial = :1", tut)
    

    If it doesn’t, you can always try:

    chaps = db.GqlQuery("SELECT * FROM Chapter " +
                            "WHERE tutorial = KEY('Tutorial', :1)", tut.id() or tut.name())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I have two models like this: class OptionsAndFeatures(models.Model): options = models.TextField(blank=True, null=True) entertainment =
In this situation I have two models, Comment and Score. The relationship is defined
I have a two models set up like this: class User < ActiveRecord::Base #
I have a simple has_one/belongs_to relationship between two models. This is a new association
Hi I'm currently going through a tutorial on unit tests. I have two models:
I stumbled over this passage in the Django tutorial : Django models have a
I been struggeling with this problem for two days now and have still not
I have looked at two of Microsoft's tutorials for MVC. In one tutorial they
I have a Profile model and two ActiveRecord::Relations of this model. SQL request of

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.