Skip to content

PostgresPartitionedModels cannot be used as abstract models #190

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

Open
wesleykendall opened this issue Sep 13, 2022 · 0 comments
Open

PostgresPartitionedModels cannot be used as abstract models #190

wesleykendall opened this issue Sep 13, 2022 · 0 comments
Labels
bug table-partitioning Features/bugs related to table partitioning.

Comments

@wesleykendall
Copy link

wesleykendall commented Sep 13, 2022

For example:

class PartitionedEvent(PostgresPartitionedModel):
    class PartitioningMeta:
        method = PostgresPartitioningMethod.RANGE
        key = ["pgh_created_at"]

    pgh_created_at = models.DateTimeField()

    class Meta:
        abstract = True


class ConcretePartitionEvent(PartitionedEvent):
    pass

When calling manage.py pgmakemigrations, it will produce a migration with operations that look like this:

operations = [
        psqlextra.backend.migrations.operations.create_partitioned_model.PostgresCreatePartitionedModel(
            name='ConcretePartitionEvent',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('pgh_created_at', models.DateTimeField()),
            ],
            options={
                'abstract': False,
            },
            partitioning_options={
                'method': psqlextra.types.PostgresPartitioningMethod['RANGE'],
                'key': [],
            },
            bases=(psqlextra.models.partitioned.PostgresPartitionedModel,),
            managers=[
                ('objects', psqlextra.manager.manager.PostgresManager()),
            ],
        ),
        psqlextra.backend.migrations.operations.add_default_partition.PostgresAddDefaultPartition(
            model_name='ConcretePartitionEvent',
            name='default',
        ),
    ]

Notice how "key" is []. This results in

django.core.exceptions.ImproperlyConfigured: Model 'ConcretePartitionEvent' is not properly configured to be partitioned. Set the `method` and `key` attributes on the `PartitioningMeta` class as a child of 'ConcretePartitionEvent'

When I simply make the parent model a concrete model, everything works as expected.

I couldn't find anything in the docs. Is this expected behavior?

Django=3.2.15
django-postgres-extra=2.0.4

@Photonios Photonios added bug table-partitioning Features/bugs related to table partitioning. labels Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug table-partitioning Features/bugs related to table partitioning.
Projects
None yet
Development

No branches or pull requests

2 participants