Tag browsing throws exceptions when you have tags of same name/different case (eg m51/M51)

16 views
Skip to first unread message

Graeme Coates

unread,
Mar 31, 2016, 6:04:55 AM3/31/16
to astrometry

Hi,

I'm being thrown an error by the tag browser on nova.astrometry.net when I try and click on a tag where there exists the same tag with different cases (eg m51/M51). The cuplrit looks like:

tag = Tag.objects.filter(text__iexact=query).get()

The .filter is returning a queryset with 2 records - if you apply .get() to this it will throw an exception (must be a queryset with 1 result) - iexact is a case insensitive search and thus why it's grabbing both values. 



To reproduce:

1. Run a search for a term like "M51" : http://nova.astrometry.net/tags?sort=&query=m51
2. Click on one of the links (returns m51 and M51) - navigates to : http://nova.astrometry.net/user_images/tag?query=M51&exact=on

This throws a multipleObjectsReturned error as follows:



Request Method: GET

Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'social.apps.django_app.default')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/django-1.6.2/lib/python/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/nova/nova/astrometry/net/views/image.py" in index_tag
  617.                     tag = Tag.objects.filter(text__iexact=query).get()
File "/usr/local/django-1.6.2/lib/python/django/db/models/query.py" in get
  310.             (self.model._meta.object_name, num))

Exception Type: MultipleObjectsReturned at /user_images/tag
Exception Value: get() returned more than one Tag -- it returned 2!

Dustin Lang

unread,
Mar 31, 2016, 9:57:54 AM3/31/16
to astrometry
Hi,

Thanks for the detailed bug report and analysis!

I tried putting in a fix.  It no longer crashes, but also doesn't show any results for "M51".  (If you want objects tagged automatically by the system, try "M 51" with a space.)

cheers,
--dustin


Reply all
Reply to author
Forward
0 new messages