2013-03-23 75 views
1

在下面的代碼片段中,當我嘗試執行這兩行時,出現此錯誤:「 BadRequestError:不能在具有相等過濾器的屬性上使用投影「BadRequestError:無法在屬性上使用等值過濾器投影

myname = self.response.get('state') 

QY1 = db.GqlQuery(* SELECT名字,phoneNumber的,說明,城市,州FROM表1 WHERE狀態= 1」,MYNAME)

我有一個循環後,這個迭代通過結果集 爲我在qy1: (做一些JSON轉儲) 現在狀態字段是一個StringProperty,甚至做str(myname)會得到相同的結果。我一直在尋找他們說你應該做我以前做過的事情,或者做一些'字符串'的狀態,但是如果我改變它,我會得到一個關於它不是列表的錯誤。

有什麼建議嗎?

完整的堆棧跟蹤是:

INFO  2013-03-23 14:12:08,756 dev_appserver.py:3103] "POST /sendNearByPlaces.html HTTP/1.1" 500 - 
ERROR 2013-03-23 14:12:22,023 webapp2.py:1552] cannot use projection on a property with an equality filter 
Traceback (most recent call last): 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "C:\Users\defiant\Desktop\PythonServer\bar.py", line 368, in post 
    for i in qy1: 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 2326, in next 
    return self.__model_class.from_entity(self.__iterator.next()) 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_query.py", line 2892, in next 
    next_batch = self.__batcher.next() 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_query.py", line 2754, in next 
    return self.next_batch(self.AT_LEAST_ONE) 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_query.py", line 2791, in next_batch 
    batch = self.__next_batch.get_result() 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 604, in get_result 
    return self.__get_result_hook(self) 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_query.py", line 2528, in __query_result_hook 
    self._batch_shared.conn.check_rpc_success(rpc) 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\datastore\datastore_rpc.py", line 1224, in check_rpc_success 
    raise _ToDatastoreError(err) 
BadRequestError: cannot use projection on a property with an equality filter 
INFO  2013-03-23 14:12:22,075 dev_appserver.py:3103] "POST /sendNearByPlaces.html HTTP/1.1" 500 - 
+0

請張貼異常的完整堆棧跟蹤,我有一種感覺,它不是失敗,你的事情失敗。 – 2013-03-23 14:01:19

+0

我已經添加了堆棧跟蹤。 – user2202316 2013-03-23 14:18:46

+0

'SELECT * FROM'不是投影查詢。你在使用'SELECT propertyName FROM'的地方發生錯誤嗎? – 2013-03-23 17:53:22

回答

1

按照documentation「你不能預計,也是在一個平等的過濾器中引用的屬性例如選擇距離種,其中A =不支持1,但SELECT A FROM kind WHERE B = 1或SELECT A FROM kind WHERE A> 1 is supported。「

[編輯] 簡而言之:

qy1=db.GqlQuery(*SELECT name,phoneNumber,description,city,state FROM Table1 WHERE state =:1",myname) # WRONG 
qy1=db.GqlQuery(*SELECT name,phoneNumber,description,city  FROM Table1 WHERE state =:1",myname) # CORRECT 

[/編輯]

+0

文檔移動到這裏:https://developers.google.com/appengine/docs/python/datastore/projectionqueries#Limitations_on_Projections – Dave 2013-05-23 23:11:05

+0

此外,這是一個任意規則,我知道有作爲投影查詢的限制來自索引而不是直接來自數據存儲區,但我無法弄清楚這個特定限制背後的原因。 – Dave 2013-05-23 23:13:53

+0

實際上,我所知道的鏈接ovided是我想讓你看到的...簡而言之,它說的是 qy1 = db.GqlQuery(* SELECT name,phoneNumber,description,city,state FROM Table1 WHERE state =:1「,myname)is wrong while qy1 = db.GqlQuery(* SELECT name,phoneNumber,description FROM table1 WHERE state = 1,myname)是正確的。 在投影查詢中,您無法在平等篩選器中選擇WHERE子句中的屬性(在本例中爲「狀態」)。這正是什麼錯誤告訴你「BadRequestError:不能使用投影在一個屬性與平等過濾器」 查看編輯 – nizz 2013-05-24 14:27:38