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

Other options are ignored by migration algorithm #570

Open
ClundXIII opened this issue Jan 15, 2024 · 1 comment
Open

Other options are ignored by migration algorithm #570

ClundXIII opened this issue Jan 15, 2024 · 1 comment

Comments

@ClundXIII
Copy link

ClundXIII commented Jan 15, 2024

Lets take a model like this:

class Test(PolymorphicModel):
  created_date = models.DateTimeField(default=timezone.now)

  class Meta:
    ordering = ['-created_date']

With an initial migration:

        migrations.CreateModel(
            name='Test',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_date', models.DateTimeField(default=django.utils.timezone.now)),
                ('polymorphic_ctype', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_%(app_label)s.%(class)s_set+', to='contenttypes.contenttype')),
            ],
            options={
                'abstract': False,
                'base_manager_name': 'objects',
                'ordering': ['-created_date'],
            },
        ),

Note, that I merged the order and polymorphic options together. Unfortunately django fails to recognize the ordering option and will create this migrations when running makemigrations;

        migrations.AlterModelOptions(
            name='Test',
            options={'ordering': ['-created_date']},
        ),

This is not a big deal and an has an easy workaround just appending the options below. However my guess would be that there is some super() call missing inside the Polymorphic handling of CreateModel. So this might be a symptom of an issue that is deep down in the code.

@j-antunes
Copy link
Contributor

Thanks for bringing this up. Please feel free to dive into the code and see if there is a potential fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants