question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abstract classes don't work anymore

See original GitHub issue

I can’t get extra fields inheriting from an abstract class. Is that feature still available? Example:

from tortoise.models import Model
from tortoise import fields


class AbstractModel(Model):
    new_field = fields.CharField(max_length=100)

    class Meta:
        abstract = True


class ModelOne(AbstractModel):
    id = fields.IntField(pk=True)
    name = fields.TextField()

After schema initialization we got only id & name fields in ModelOne:

postgres=# \d modelone
                            Table "public.modelone"
 Column |  Type   | Collation | Nullable |               Default
--------+---------+-----------+----------+--------------------------------------
 id     | integer |           | not null | nextval('modelone_id_seq'::regclass)
 name   | text    |           | not null |
Indexes:
    "modelone_pkey" PRIMARY KEY, btree (id)

There is no new_field here.

PS: tortoise-orm==0.14.0, asyncpg==0.19.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
RafRafcommented, Nov 13, 2019

Well done. 👍 Thank you!!

0reactions
grigicommented, Nov 11, 2019

I just released v0.14.2, please test that it resolved the issue for you 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Why not abstract fields? - Stack Overflow
You can do what you described by having a final field in your abstract class that is initialised in its constructor (untested code):...
Read more >
Do we need abstract classes anymore when we have Java 8's ...
For defining variables that are not final we do need abstract classes why because in interfaces by default all variables are static and...
Read more >
Abstract Classes
Generally, abstract classes can specify all the standard class components: constructors, methods, and instance variables. Again, a class must be defined with ...
Read more >
What is the point of an abstract class? : r/learnprogramming
An abstract class starts to make more sense when you deal with a large codebase and you are working with other devs (at...
Read more >
Abstract Classes and Methods - Learn Abstraction in Java
Full Java Course: https://course.alexlorenlee.com/ courses /learn-java-fastGet my favorite programming audiobook for free!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found