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

Fixed #26304 -- Handled unmanaged through table between two managed models in table introspection. #6231

Closed
wants to merge 1 commit into from

Conversation

schinckel
Copy link
Contributor

tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many
if not f.remote_field or
not f.remote_field.through or
f.remote_field.through._meta.managed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All m2m fields should have remote_field.through defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. I originally wrote the patch on 1.4 (don't ask), which has f.rel: which wasn't always set (or f.rel.through wasn't always there), and the subsequent checks were also required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think f.remote_field.through should always be available.

@charettes
Copy link
Member

Actually I think the test should be added to the introspection test app instead. You should be able to add a ManyToManyField to one of the existing models in this test app to also prevent table unnecessary table creation.

@schinckel
Copy link
Contributor Author

Yeah, there is already stuff there. I'll move it. Thanks.

@@ -6,7 +6,7 @@
from django.db.utils import DatabaseError
from django.test import TransactionTestCase, mock, skipUnlessDBFeature

from .models import Article, City, Reporter
from .models import Article, City, Reporter, ArticleReporter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put ArticleReporter after Article to appease isort.

@MarkusH MarkusH changed the title Handle unmanaged through table between two managed models. Fixed #26304 -- Handle unmanaged through table between two managed models. Mar 2, 2016
@MarkusH MarkusH changed the title Fixed #26304 -- Handle unmanaged through table between two managed models. Fixed #26304 -- Handled unmanaged through table between two managed models Mar 2, 2016
def test_unmanaged_through_model(self):
table_name = ArticleReporter._meta.db_table
connection.cursor().execute('CREATE VIEW {} AS SELECT 1 AS id'.format(table_name))
tables = connection.introspection.django_table_names(only_existing=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested locally and confirmed the view creation is not necessary.

Make sure you don't pass only_existing=True to the django_table_names call and the test will fail without the fix applied and pass with it.

@charettes
Copy link
Member

Please squash all your commits into a single one with the PR's title as body.

@schinckel schinckel force-pushed the unmanaged-through-model branch 2 times, most recently from c7033a5 to 0383e28 Compare March 2, 2016 05:59
@@ -45,6 +45,7 @@ class Article(models.Model):
body = models.TextField(default='')
reporter = models.ForeignKey(Reporter, models.CASCADE)
response_to = models.ForeignKey('self', models.SET_NULL, null=True)
unmanaged_reporters = models.ManyToManyField(Reporter, through='introspection.ArticleReporter')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify the 'introspection' prefix here.

@timgraham timgraham changed the title Fixed #26304 -- Handled unmanaged through table between two managed models Fixed #26304 -- Handled unmanaged through table between two managed models in table introspection. Mar 2, 2016
@timgraham
Copy link
Member

merged in 60633ef, thanks!

@timgraham timgraham closed this Mar 2, 2016
@schinckel schinckel deleted the unmanaged-through-model branch April 20, 2016 06:36
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

Successfully merging this pull request may close these issues.

3 participants