afsmith / cc

chinchilla
0 stars 0 forks source link

MultipleObjectsReturned: get() returned more than one File -- it returned 2! #172

Closed afsmith closed 10 years ago

afsmith commented 10 years ago

Viewing the report view: https://cc.kneto.com/report/587/ looks to cause this....

Traceback (most recent call last):

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
   response = view_func(request, *args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
   return view_func(request, *args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/annoying/decorators.py", line 74, in wrapper
   output = function(request, *args, **kwargs)

 File "/opt/kneto/cc/project/cc/apps/reports/views.py", line 78, in report_detail_per_file
   f = this_message.files.get(index=file_index)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
   return self.get_query_set().get(*args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/db/models/query.py", line 407, in get
   (self.model._meta.object_name, num))

MultipleObjectsReturned: get() returned more than one File -- it returned 2!

<WSGIRequest
path:/report/detail/587/5/,
GET:<QueryDict: {}>,
POST:<QueryDict: {u'file_index': [u'5'], u'message_id': [u'587']}>,
COOKIES:{'__utma': '30793773.1419360216.1393580813.1401268655.1401284835.161',
'__utmb': '30793773.41.10.1401284835',
'__utmc': '30793773',
'__utmz': '30793773.1400239618.141.8.utmcsr=kneto.com|utmccn=(referral)|utmcmd=referral|utmcct=/pricing/',
'_ga': 'GA1.2.1503909700.1400238990',
'cookielaw_accepted': '1',
'csrftoken': 'FaJgXi2g60Ahd3nBbtn8g6V6vfrtmgHg',
'sessionid': 'gs0ojt1bymtltoiymlusrid8s04zhnke'},
META:{'CONTENT_LENGTH': '27',
'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
u'CSRF_COOKIE': u'FaJgXi2g60Ahd3nBbtn8g6V6vfrtmgHg',
u'CSRF_COOKIE_USED': True,
'HTTP_ACCEPT': '*/*',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',
'HTTP_CACHE_CONTROL': 'no-cache',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=FaJgXi2g60Ahd3nBbtn8g6V6vfrtmgHg; sessionid=gs0ojt1bymtltoiymlusrid8s04zhnke; __utma=30793773.1419360216.1393580813.1401268655.1401284835.161; __utmz=30793773.1400239618.141.8.utmcsr=kneto.com|utmccn=(referral)|utmcmd=referral|utmcct=/pricing/; cookielaw_accepted=1; _ga=GA1.2.1503909700.1400238990; __utmc=30793773; __utmb=30793773.41.10.1401284835',
'HTTP_HOST': 'cc.kneto.com',
'HTTP_PRAGMA': 'no-cache',
'HTTP_REFERER': 'https://cc.kneto.com/report/587/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0',
'HTTP_X_CSRFTOKEN': 'FaJgXi2g60Ahd3nBbtn8g6V6vfrtmgHg',
'HTTP_X_FORWARDED_FOR': '82.181.170.197',
'HTTP_X_FORWARDED_PROTOCOL': 'https',
'HTTP_X_REAL_IP': '82.181.170.197',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'PATH_INFO': u'/report/detail/587/5/',
'QUERY_STRING': '',
'RAW_URI': '/report/detail/587/5/',
'REMOTE_ADDR': '82.181.170.197',
'REMOTE_PORT': '80',
'REQUEST_METHOD': 'POST',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'cc.kneto.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SOFTWARE': 'gunicorn/18.0',
'gunicorn.socket': <socket._socketobject object at 0x2a96590>,
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f4bf73d5270>,
'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0xf21ae0>,
'wsgi.input': <gunicorn.http.body.Body object at 0x2aac990>,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>
hieuh25 commented 10 years ago

Do you remember how did you create this message? It's so weird that it has 2 files with the same index and I don't know how to reproduce the same message. So the tokens in the message were correctly inserted but the file indexes were: 1, 2, 4, 5, 5 so you must did something special to get this corner case.

afsmith commented 10 years ago

I was just able to recreate the issue by attaching the same file 5 times. This also resulted in the display error: [link1] 1 2 [link4] 3

Yes, a corner case.... :) But people will do it :(

Traceback (most recent call last):

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
   response = view_func(request, *args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
   return view_func(request, *args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/annoying/decorators.py", line 74, in wrapper
   output = function(request, *args, **kwargs)

 File "/opt/kneto/cc/project/cc/apps/reports/views.py", line 78, in report_detail_per_file
   f = this_message.files.get(index=file_index)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
   return self.get_query_set().get(*args, **kwargs)

 File "/opt/kneto/cc/local/lib/python2.7/site-packages/django/db/models/query.py", line 407, in get
   (self.model._meta.object_name, num))

MultipleObjectsReturned: get() returned more than one File -- it returned 3!

<WSGIRequest
path:/report/detail/592/5/,
GET:<QueryDict: {}>,
POST:<QueryDict: {u'file_index': [u'5'], u'message_id': [u'592']}>,
COOKIES:{'__utma': '30793773.1419360216.1393580813.1401284835.1401350980.162',
'__utmb': '30793773.11.10.1401350980',
'__utmc': '30793773',
'__utmz': '30793773.1401350980.162.9.utmcsr=github.com|utmccn=(referral)|utmcmd=referral|utmcct=/afsmith/cc/issues/172',
'_ga': 'GA1.2.1503909700.1400238990',
'cookielaw_accepted': '1',
'csrftoken': 'Ua43ZpuGfIsqTxCxY5AIw9E6hbhas1WD',
'sessionid': 'de4tq73vgv5u5lqts0ko0m72hkbmhd7e'},
META:{'CONTENT_LENGTH': '27',
'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
u'CSRF_COOKIE': u'Ua43ZpuGfIsqTxCxY5AIw9E6hbhas1WD',
u'CSRF_COOKIE_USED': True,
'HTTP_ACCEPT': '*/*',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.5',
'HTTP_CACHE_CONTROL': 'no-cache',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=Ua43ZpuGfIsqTxCxY5AIw9E6hbhas1WD; sessionid=de4tq73vgv5u5lqts0ko0m72hkbmhd7e; __utma=30793773.1419360216.1393580813.1401284835.1401350980.162; __utmz=30793773.1401350980.162.9.utmcsr=github.com|utmccn=(referral)|utmcmd=referral|utmcct=/afsmith/cc/issues/172; cookielaw_accepted=1; _ga=GA1.2.1503909700.1400238990; __utmb=30793773.11.10.1401350980; __utmc=30793773',
'HTTP_HOST': 'cc.kneto.com',
'HTTP_PRAGMA': 'no-cache',
'HTTP_REFERER': 'https://cc.kneto.com/report/592/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0',
'HTTP_X_CSRFTOKEN': 'Ua43ZpuGfIsqTxCxY5AIw9E6hbhas1WD',
'HTTP_X_FORWARDED_FOR': '82.181.170.197',
'HTTP_X_FORWARDED_PROTOCOL': 'https',
'HTTP_X_REAL_IP': '82.181.170.197',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'PATH_INFO': u'/report/detail/592/5/',
'QUERY_STRING': '',
'RAW_URI': '/report/detail/592/5/',
'REMOTE_ADDR': '82.181.170.197',
'REMOTE_PORT': '80',
'REQUEST_METHOD': 'POST',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'cc.kneto.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SOFTWARE': 'gunicorn/18.0',
'gunicorn.socket': <socket._socketobject object at 0x2b5a360>,
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7f4bf73d5270>,
'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0xf21ae0>,
'wsgi.input': <gunicorn.http.body.Body object at 0x292e350>,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>