Skip to content
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

Property fields and inhertinace #774

Closed
javiergallo opened this issue Aug 4, 2022 · 1 comment
Closed

Property fields and inhertinace #774

javiergallo opened this issue Aug 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@javiergallo
Copy link

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
@javiergallo javiergallo added the bug Something isn't working label Aug 4, 2022
collerek added a commit that referenced this issue Oct 21, 2022
* Fix property_fields not being inherited. Fix for #774.

* Fix coverage

* Fix coverage by removing set attribute update - during inheriting the current property fields are not set yet.
@collerek
Copy link
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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants