BadRequestError: cannot use projection on a property with an equality filter

326 views
Skip to first unread message

Afzal Shahul Hameed

unread,
May 8, 2017, 2:47:50 AM5/8/17
to appengine-ndb-discuss, Vidyanand Murunnikara
I need to query on a property based on a list of values and then need to group the fetched rows as per the property. So if I cannot use projection on the property with an equality filter, is my only alternative to do number of queries as per the number of values in the list!?

Ideally I would do this;

        foos_grouped_by_property_1 = ndb.Query(
            kind='Foo',
            projection=[Foo.property_1, Foo.property_2, ],
            group_by
=[Foo.property_1, ]).filter(
                Foo.property_1.IN(property_1_possible_values)).fetch()


But I can do only this!?;

    foos_grouped_by_property_1 = {}
    for possible_value in property_1_possible_values:
        foos_grouped_by_property_1[possible_value] = Foo.query(Foo.property_1 == possible_value).fetch(
            projection=[Foo.property_2, ]))    




Afzal Shahul Hameed

unread,
May 8, 2017, 5:35:36 AM5/8/17
to appengine-ndb-discuss, vidy...@tarams.com
Doing this currently;

        foos = Foo.query(Foo.property_1.IN(property_1_possible_values)).fetch()
        foos_grouped_by_property_1 = defaultdict(list)
        for foo in foos:
            foos_grouped_by_property_1[foo.property_1].append(foo)

Guido van Rossum

unread,
May 8, 2017, 2:31:20 PM5/8/17
to appengine-...@googlegroups.com, vidy...@tarams.com
Nobody is active on this list any more.

=============================
DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Further, this e-mail may contain viruses and all reasonable precaution to minimize the risk arising there from is taken by Tarams. Tarams is not liable for any damage sustained by you as a result of any virus in this e-mail. All applicable virus checks should be carried out by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=============================

--
You received this message because you are subscribed to the Google Groups "appengine-ndb-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appengine-ndb-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Collins

unread,
May 9, 2017, 1:06:57 PM5/9/17
to appengine-ndb-discuss, vidy...@tarams.com
Reply all
Reply to author
Forward
0 new messages