Skip to content

Property fields and inhertinace #774

@javiergallo

Description

@javiergallo

Property fields are not inherited by submodels:

class BaseFoo(ormar.Model):
    class Meta:
        abstract = True

    name: str = ormar.String(max_length=100)

    @ormar.property_field
    def prefixed_name(self) -> str:
        return "prefix_" + self.name


class Foo(BaseFoo):
    class Meta:
        metadata = metadata
        database = database
 
    id: int = ormar.Integer(primary_key=True)

foo = Foo(name="foo")

Expected behavior

>>> foo.prefixed_name
'prefix_foo'

foo.json()
'{"name": "foo", "id": null, "prefixed_name": "prefix_foo"}' 

Actual behavior

>>> foo.prefixed_name
<bound method BaseFoo.prefixed_name of Foo({'name': 'foo', 'id': None})>

>>> foo.json()
'{"name": "foo", "id": null}'  # "prefixed_name" is missing

Versions

  • Database backend used: postgresql
  • Python version: 3.8.10
  • ormar version: 0.11.2
  • pydantic version: 1.8.2

Activity

collerek

collerek commented on Oct 21, 2022

@collerek
Owner

Fixed in 0.12.0, please update and check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @javiergallo@collerek

        Issue actions

          Property fields and inhertinace · Issue #774 · collerek/ormar