Skip to content

StructuredProperty not using correct names when generating queries. #449

@Lukasz-Gillner

Description

@Lukasz-Gillner

I encountered an issue while migrating to cloud ndb. When querying entities based on a value contained in a StructuredProperty the structured property does not use code name but uses the datastore name instead. Below is a short code to replicate the issue

from google.cloud import ndb

class StructPropModel(ndb.Model):
    code_name = ndb.IntegerProperty('datastore_name')

class EntityModel(ndb.Model):
    structured_variable = ndb.StructuredProperty(StructPropModel)

def test_error():
    test_entity = EntityModel()
    test_entity.structured_variable = StructPropModel(code_name=1)
    test_entity.put()
    results = EntityModel.query(EntityModel.structured_variable.code_name == 1).count()
    # Raises
    # AttributeError: Model subclass StructPropModel has no attribute code_name

For completeness sake, the issue occurred on python 2.7 using google-cloud-ndb 1.2.1

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the googleapis/python-ndb API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions