dynamorm icon indicating copy to clipboard operation
dynamorm copied to clipboard

Is Table inheritance possible?

Open Quidge opened this issue 5 years ago • 3 comments

Is building the Dynamodel's subclass Table attribute through inheritance supported?

class BaseTable:
    hash_key = 'someid'
    read = 3
    write = 4


class ActualTable(DynaModel):
    class Table(BaseTable):
        name = 'table-name'

    class Schema:
        someid = fields.String(required=True)

Doing so raises dynamorm.exceptions.MissingTableAttribute: Missing required Table attribute: hash_key errors. I see that the dynamorm metaclass is doing some fancy stuff behind the scenes with the Table attribute, but it does that with Schemas too and Schema inheritance is supported now.

Is there a suggested way to do what I'm looking for with Table inheritance?

Quidge avatar Jan 23 '20 14:01 Quidge

We don't currently support Table inheritance because of the way our meta-class works. We would need to do something similar to #46 where we added support for inheritance on the Model.

borgstrom avatar Feb 06 '20 01:02 borgstrom

Great to know, thank you @borgstrom !

Quidge avatar Feb 09 '20 15:02 Quidge

I'm assuming you can't sufficiently predict the table name beforehand? I use a function to generate part of the table name dynamically (for dev/staging/prod).

On Thu, Jun 18, 2020 at 5:58 AM Thomas Passer Jensen < [email protected]> wrote:

Does a workaround exist for when the table named is not known when the model class is defined? When a table is defined in CloudFormation without the TableName attribute it receives an autogenerated "unique physical ID".

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NerdWalletOSS/dynamorm/issues/96#issuecomment-645915936, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABR2MRNSY5VMO2UMUUGJA7DRXHQNDANCNFSM4KKXQKNQ .

Quidge avatar Jun 21 '20 02:06 Quidge