-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NDB: Query with UserProperty results in "An entity value is not allowed" error #1002
Comments
It looks some wired logic in your code. You declare a class name TestModel. class TestModel(ndb.Model):
owner = ndb.UserProperty() Then you import a custom module with the same name. from junyi.activity.test_model import TestModel
...
test_model = TestModel(owner=user) Won't it be conflicts when you invoke it? |
Apologies for the confusion. I've simplified the sample code to make it more straightforward and reproducible. Please check if the following code works for you
|
With removing Actually, this error "An entity value is not allowed" mostly occurs when you attemp to store types like The line A solution is that using custom defined property to store data such as email. You can create a user instances with Here is an example based on amended your code: import os
import sys
from google.appengine.api import users
from google.cloud import ndb
class TestModel(ndb.Model):
owner_email = ndb.StringProperty()
def init_ndb():
os.environ["AUTH_DOMAIN"] = "example.com"
ndb_client = ndb.Client(project="example-project")
return ndb_client
def test_get_user_data():
ndb_client = init_ndb()
with ndb_client.context():
user = users.User(email="[email protected]")
test_model = TestModel(owner_email=user.email())
test_model.put()
query = TestModel.query().filter(TestModel.owner_email == user.email())
result = query.get()
print("result", result)
if __name__ == "__main__":
test_get_user_data() And the result of query is: result TestModel(key=Key('TestModel', 5644004762845184), owner_email='[email protected]') |
@fbukevin
|
Sorry about the confused wording. The meaning of the statement is that if you attempt to store type |
Thank you, @fbukevin . We are migrating from |
python-ndb/google/cloud/ndb/model.py Lines 3240 to 3243 in c55ec62
According to the comment, this issue can be resolved by adding
This was done using a temporary hack in the code:
Looking forward to a better fix, where the correct |
Hi @youchenlee , You can achieve your requirement like this as a workaround. I suggest you can create a pull request with your fixing. |
Reproduce steps
import os
import sys
from google.appengine.api import users
from google.cloud import ndb
class TestModel(ndb.Model):
owner = ndb.UserProperty()
def init_ndb():
os.environ["AUTH_DOMAIN"] = "ikala.ai"
ndb_client = ndb.Client(project="cloud-sa-sandbox-1")
return ndb_client
def test_get_user_data():
ndb_client = init_ndb()
with ndb_client.context():
user = users.User(email="[email protected]")
test_model = TestModel(owner=user)
test_model.put()
query = TestModel.query().filter(TestModel.owner == user)
result = query.get()
print("result", result)
if __name__ == "__main__":
test_get_user_data() Demo screenshot_20241105151059.mp4 |
I've submitted PR #1004 to fix this issue. The root cause has been identified: UserProperty meanings need to be handled at the entity's top level in the Datastore, but this wasn't being properly set during query filter creation. The fix implements proper meaning propagation in the This should restore the ability to filter by UserProperty fields as expected. |
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
Environment details
Steps to reproduce
Code example
Stack trace
Thanks!
The text was updated successfully, but these errors were encountered: