Skip to content

Custom classes inheriting Entity cannot be constructed from entities #396

@ghost

Description

Currently the following doesn't work:

class Foo(Entity):
    def bar(self):
        """ behavior dependent on internal properties such as _key """
ent = dataset.entity()
baz = Foo(ent)
baz.bar()

This is inconsistent with Entity inheriting dict. Besides style issues, I would think sub-classing Entity would be the preferred way to introduce custom behavior, or enforce an entity schema.

Current workaround is:

class Foo(Entity):
    def __init__(self, ent):
         self._entity = ent
    def bar(self):
         """ behavior dependent on _entity """

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions