[Django] #19511: Thread safe bound method weakrefs

8 views
Skip to first unread message

Django

unread,
Dec 23, 2012, 1:12:29 PM12/23/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------
Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I'm often getting this traceback:
{{{
AttributeError: 'BoundMethodWeakref' object has no attribute
'deletionMethods'

Stacktrace (most recent call last):

File "django/core/handlers/base.py", line 119, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "posts/views.py", line 404, in get
posts_post.save()
File "django/db/models/base.py", line 475, in save
self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
File "django/db/models/base.py", line 506, in save_base
signals.pre_save.send(sender=origin, instance=self, raw=raw,
using=using)
File "django/dispatch/dispatcher.py", line 183, in send
response = receiver(signal=self, sender=sender, **named)
File "haystack/models.py", line 268, in load_indexes
ui.setup_indexes()
File "haystack/utils/loading.py", line 283, in setup_indexes
index._setup_save()
File "celery_haystack/indexes.py", line 33, in _setup_save
signals.post_save.connect(self._enqueue_save, sender=model,
dispatch_uid=CelerySearchIndex)
File "django/dispatch/dispatcher.py", line 105, in connect
receiver = saferef.safeRef(receiver, onDelete=self._remove_receiver)
File "django/dispatch/saferef.py", line 29, in safeRef
onDelete=onDelete
File "django/dispatch/saferef.py", line 248, in get_bound_method_weakref
return BoundMethodWeakref(target=target, onDelete=onDelete)
File "django/dispatch/saferef.py", line 88, in __new__
current.deletionMethods.append( onDelete)
}}}

I suspect this has something to do with the threading environment I'm
using. I'm attaching a patch that I believe fixes the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 23, 2012, 1:13:43 PM12/23/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------

Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Kronuz):

* cc: Kronuz (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:1>

Django

unread,
Dec 24, 2012, 8:22:59 AM12/24/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------

Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by apollo13):

#19510 was a duplicate.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:2>

Django

unread,
Dec 24, 2012, 8:28:11 AM12/24/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by apollo13):

* status: new => closed
* resolution: => fixed


Comment:

Did you attach the wrong patch here?

Django

unread,
Dec 24, 2012, 8:30:44 AM12/24/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------

Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by apollo13):

* status: closed => new
* resolution: fixed =>


Comment:

Wth did the resolution get set to fixed :/

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:3>

Django

unread,
Dec 31, 2012, 2:45:44 PM12/31/12
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by aaugustin):

* status: new => closed

* resolution: => needsinfo


Comment:

This may be a valid issue, but the description doesn't include enough
information to reproduce it and the wrong patch was attached.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:4>

Django

unread,
Jan 5, 2013, 1:29:56 PM1/5/13
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
-------------------------------+--------------------------------------

Reporter: Kronuz | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Kronuz):

* status: closed => new

* resolution: needsinfo =>


Comment:

Sorry I attached the wrong file, I've just attached the correct one.

The problem seems to be the `BoundMethodWeakref._allInstances` is filled
with an uninitialised object, and when/if another thread tries to get and
use the object, it doesn't still have at least the `deletionMethods`
attribute which is added durin the call to `__init__()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:5>

Django

unread,
Jan 14, 2013, 11:36:49 PM1/14/13
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
------------------------------+------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by akaariai):

* type: Uncategorized => Bug
* component: Uncategorized => Core (Other)
* stage: Unreviewed => Accepted


Comment:

The explanation seems correct to me. It also seems this will be impossible
to test. You will need to switch to another thread in between the dict
assignment and the `__init__()` call, and then you need to access the same
key in another thread. An unlikely scenario.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:6>

Django

unread,
Feb 9, 2014, 5:43:29 AM2/9/14
to django-...@googlegroups.com
#19511: Thread safe bound method weakrefs
------------------------------+------------------------------------
Reporter: Kronuz | Owner: nobody
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.4
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by mjtamlyn):

* status: new => closed

* resolution: => invalid


Comment:

Our implementation of weakrefs has now gone in favour of (backported) code
from python 3.4. This should hopefully no longer be an issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/19511#comment:7>

Reply all
Reply to author
Forward
0 new messages