Code

Opened 17 months ago

Closed 6 months ago

#19774 closed Cleanup/optimization (fixed)

contentypes generic module has core functionality plus admins-specific one

Reported by: ramiro Owned by: ramiro
Component: contrib.contenttypes Version: master
Severity: Normal Keywords: dependency generic contenttypes
Cc: loic@…, charettes Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

(Copied and adapted from https://code.djangoproject.com/ticket/16368#comment:16)

Consider a project with a foo and a bar apps listed on INSTALLED_APPS:

  • foo uses generic foreign keys, with the following models.py:
    from django.db import models
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.contenttypes import generic
    
    class TaggedItem(models.Model):
        tag = models.SlugField()
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        content_object = generic.GenericForeignKey()
    
  • bar has a Site model:
    from django.db import models
    
    class Site(models.Model):
        name = models.CharField(...
        # ...
    
  • Neither the admin nor sites Django apps are being used.

This causes the user's Site model to be overridden and masked by Django sites framework's one.

This is because the django/contrib/contenttypes/generic.py module contain both the definitions of the model-related generic stuff (GenericForeignKey, etc.) AND the admin app-related specialized inlines (GenericInlineModelAdmin, GenericStackedInline, GenericTabularInline.)

Maybe it's time we move the latter ones from django.contrib.contenttypes.generic to, say, a new generic_admin (or admin_tools?) on django.contrib.contenttypes?. Of course this would need a deprecation process.

Attachments (0)

Change History (12)

comment:1 Changed 17 months ago by wim@…

  • Keywords dependency generic contenttypes added
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

comment:2 Changed 16 months ago by ramiro

  • Description modified (diff)
  • Owner changed from nobody to ramiro
  • Status changed from new to assigned

comment:3 Changed 6 months ago by loic84

  • Cc loic@… added

comment:4 Changed 6 months ago by charettes

As discussed on IRC with ramiro and loic splitting the generic module into fields and admin and deprecating the former should fix the issue.

I couldn't reproduce the Site cloaking with you described example against 1.6 and master. The only way I managed to reproduce is by having a sites app, just like it's described in #16368.

comment:5 Changed 6 months ago by charettes

  • Cc charettes added

comment:6 Changed 6 months ago by charettes

  • Has patch set
  • Needs documentation set
  • Patch needs improvement set

@ramiro, I created a PR missing release notes and documentation adjustment. I'll try to work on it in the new few days but if you want to pick it up from here feel free to do it.

Last edited 6 months ago by charettes (previous) (diff)

comment:7 Changed 6 months ago by charettes

  • Patch needs improvement unset

I adjusted the documentation and added a release note. The PR should be ready for review.

comment:8 Changed 6 months ago by loic84

  • Needs documentation unset
  • Triage Stage changed from Accepted to Ready for checkin

Looks good to me, I'm pretty happy with the forms.py, fields.py, admin.py split up.

comment:9 Changed 6 months ago by carljm

Looks good to me; good idea to remove everything from that module and just deprecate the module, that's a lot simpler than the previous approach.

I won't claim to have reviewed all the minor changes to docs and tests in detail, but I assume if you've run the tests and they are warning-free that that was all done correctly. Looks good to me!

comment:10 Changed 6 months ago by carljm

(I did make a couple comments on wording of docs and error messages.)

comment:11 Changed 6 months ago by ramiro

Simon,

I had some unfinished work in that direction and was a bit uncomfortable about still having the formset definition in the new fields module. Good call on creating forms.py

Please go ahead, my review didn't find anything.

comment:12 Changed 6 months ago by Simon Charette <charette.s@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 10e3faf191d8f230dde8534d1c8fad8c8717816e:

Fixed #19774 -- Deprecated the contenttypes.generic module.

It contained models, forms and admin objects causing undesirable
import side effects. Refs #16368.

Thanks to Ramiro, Carl and Loïc for the review.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.