Code

Opened 6 years ago

Closed 6 years ago

#7147 closed (duplicate)

archive_index and archive_year create a query with "date_field IS NULL"

Reported by: Guillaume Lederrey <guillaume.lederrey@…> Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

While using django.views.generic.date_based.archive_index or archive_year, the following SQL query is generated at http://code.djangoproject.com/browser/django/trunk/django/views/generic/date_based.py#L28 :

SELECT DISTINCT CAST(DATE_FORMAT(`news_news`.`publication_date`, '%Y-01-01 00:00:00') AS DATETIME)
FROM `news_news`
WHERE `news_news`.`publication_date` IS NULL ORDER BY 1 ASC

As this query returns an empty set, the "latest" variable is never loaded from DB at http://code.djangoproject.com/browser/django/trunk/django/views/generic/date_based.py#L32

I cant understand why the "publication_date IS NULL". In my understanding, if anything it should be "IS NOT NULL".

I dont know the Query system well, but it seems that archive_index and archive_year use a DateQuery. archive_month doesnt have this problem. So the problem might be related more to DateQuery than to gneric views ...

I have the following urls.py

    url(r'^$',
        date_based.archive_index,
        {
            'queryset' : News.objects.all(),
            'date_field' : 'publication_date',
            'allow_future' : True,
        },
    ),
    url(r'^(?P<year>\d{4})/$',
        date_based.archive_year,
        {
            'queryset' : News.objects.all(),
            'date_field' : 'publication_date',
            'allow_future' : True,
            'make_object_list' : True,
        },
    ),

and the following models.py

class News(models.Model):
    """ News model """
    title = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(prepopulate_from=("title",),
                            unique_for_date='publication_date')
    author = models.ForeignKey(User)
    creation_date  = models.DateField(auto_now_add=True)
    modification_date = models.DateField(auto_now=True)
    publication_date = models.DateField(blank=True, null=True)
    ask_promotion = models.BooleanField(default=False,
                                        help_text=_("Ask for this news to be promoted on the front page. For example, an artist might be able to write news for its next gig, and have the news appear on the artist's page, but not on the front page. The artist can ask a moderator to promote the news on the front page by checking this field."))
    promoted = models.BooleanField(default=False,
                                   help_text=_("If this field is checked, the news will appear on the front page."))
    trock_news = models.BooleanField(default=False,
                                     help_text=_("Check this field if you want this news to be published in the next TrocK news."))
    text = models.TextField(blank=True)

    class Meta:
        """
        Defines meta data on the model.
        """
        verbose_name_plural = _('news')
        ordering = ['-publication_date', 'title',]
        permissions = (
            ("export_trock_news", _("Can export the list of news selected for the next TrocK news")),
        )

    class Admin:
        """
        This model is available in the admin interface.
        """
        list_display = ('title', 'publication_date',)

    def __unicode__(self):
        return '%s' % self.title

    @permalink
    def get_absolute_url(self):
        """
        The URL to this news in the date based view.
        """
        return ('news_detail', (), {
            'year' : self.publication_date.year,
            'month' : self.publication_date.month,
            'day' : self.publication_date.day,
            'slug' : self.slug,
        })

    @permalink
    def get_absolute_url_by_id(self):
        """
        The URL to this news in the ID based view.
        """
        return ('news_detail_by_id', (), {
            'object_id' : self.pk,
        })

Attachments (0)

Change History (3)

comment:1 Changed 6 years ago by Guillaume Lederrey <guillaume.lederrey@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by Gilles Fabio

Same problem. It's due to the recent queryset-refactor branch merge. Try with revision 7476, that will work. And try now with revision 7477.. Boom. Broken.

This evening, I will try to detect and correct this annoying bug.

comment:3 Changed 6 years ago by oyvind

  • Resolution set to duplicate
  • Status changed from new to closed

in favour of #7155

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.