dlamotte / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

KeyError in change_aliases #249

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This appears to still be an issue. I get this exception when performing these 
steps:

    object_list = MyTaggedObject.objects.by_partner(request.partner.id) # Manager used to filter based on a reqest id 
    tags = Tag.objects.usage_for_queryset(object_list)

    # I now want to filter this list down by year/month and tag:
    years = object_list.dates('date', 'year', order='DESC')
    months = object_list.dates('date', 'month')
    if year:
        object_list = object_list.filter(date__year=year)
    if month:
        object_list = object_list.filter(date__month=month)
    if tag:
        try:
            # Case-insensitive tag search
            filter_tag = Tag.objects.get(name__iexact=tag)
            # Find the objects for that tag
            object_list = TaggedItem.objects.get_by_model(object_list, filter_tag)
        except Tag.DoesNotExist:
            # Tag wasn't found
            object_list = object_list.none()

    # Up to this point, everything is fine... I will now *sometimes* get the Key Error exception if I try to use the set in an "in" expression:
    OtherObject.filter(my_tagged_object__in=object_set).filter(...)

I believe I get the exception depending on if the tag exists on the filtered 
object_list. 

Traceback:
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/core/handler
s/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/contrib/auth
/decorators.py" in _wrapped_view
  25.                 return view_func(request, *args, **kwargs)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/views/decora
tors/http.py" in inner
  37.             return func(request, *args, **kwargs)
File "/var/hats/releases/current/hats/core/views.py" in report_profit_view
  125.     total_money = MonetaryAmount.objects.actual(transaction_list).aggregate(sum=Sum('amount'))['sum'] or 0
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/qu
ery.py" in aggregate
  313.         return query.get_aggregation(using=self.db)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/query.py" in get_aggregation
  366.         result = query.get_compiler(using).execute_sql(SINGLE)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/compiler.py" in execute_sql
  717.             sql, params = self.as_sql()
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/compiler.py" in as_sql
  65.         where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/where.py" in as_sql
  91.                     sql, params = child.as_sql(qn=qn, connection=connection)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/where.py" in as_sql
  94.                     sql, params = self.make_atom(child, qn, connection)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/where.py" in make_atom
  141.                 lvalue, params = lvalue.process(lookup_type, params_or_value, connection)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/where.py" in process
  312.                     connection=connection, prepared=True)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/fi
elds/subclassing.py" in inner
  53.             return func(*args, **kwargs)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/fi
elds/related.py" in get_db_prep_lookup
  154.                 sql, params = value._as_sql(connection=connection)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/qu
ery.py" in _as_sql
  805.             return obj.query.get_compiler(connection=connection).as_nested_sql()
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/compiler.py" in as_nested_sql
  132.         obj.bump_prefix()
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/query.py" in bump_prefix
  767.         self.change_aliases(change_map)
File 
"/var/hats/releases/current/hats/lib/python2.6/site-packages/django/db/models/sq
l/query.py" in change_aliases
  708.             alias_data = list(self.alias_map[old_alias])

Exception Type: KeyError at /home/report/TagName/
Exception Value: tagging_taggeditem

This appears to be similar to the KeyError in issue#207 
(http://code.google.com/p/django-tagging/issues/detail?id=207) however since 
the stack trace is different, I am reporting it separately. This was with the 
latest stable django-tagging version 0.3.1 and Django 1.2.1

Original issue reported on code.google.com by paulosw...@gmail.com on 11 Jul 2010 at 5:16

GoogleCodeExporter commented 8 years ago
A possibly-related question with no fix on SO: 

http://stackoverflow.com/questions/1268708/

Original comment by paulosw...@gmail.com on 11 Jul 2010 at 5:32