#22657: Can't disconnect signal if connected using @receiver tag
-------------------------------------+-------------------------------------
Reporter: michalsicker@… | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: @receiver signal | Triage Stage:
disconnect | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by anonymous):
Replying to [comment:2 bmispelon]:
Hi,
I just reproduced the issue. It's related to parameter sender, when I
don't provide that parameter, receiver is not disconnected. I know it
works for you but maybe something else influence my results, i.e. it
occurs in test case. Also the function is imported from different app. But
now I'm 100% sure, i'll paste my results.
code part:
pre_save.disconnect(calculate_current_equity)
for s in Subscription.objects.all():
# simulate real world behaviour - closing transactions one by
one in correct order
for st in
s.subscription_transactions.order_by('mt_close_time'):
st.mt_open_price =
QuoteGenerator.get_symbol_sl_value(st.symbol.name, st.type)
st.mt_close_price =
QuoteGenerator.get_symbol_sl_value(st.symbol.name, st.type)
st.mt_profit = Decimal(randint(1000, 100000) / 100)
st.save()
result:
File "[...]/webapp/signals/models.py", line 149, in
'''calculate_current_equity'''
raise CustomRuntimeError("Closed transaction saved again, although
calculations already done.")
CustomRuntimeError: Closed transaction saved again, although calculations
already done.
pre_save.disconnect(calculate_current_equity,
SubscriptionTransaction)
for s in Subscription.objects.all():
# simulate real world behaviour - closing transactions one by
one in correct order
for st in
s.subscription_transactions.order_by('mt_close_time'):
st.mt_open_price =
QuoteGenerator.get_symbol_sl_value(st.symbol.name, st.type)
st.mt_close_price =
QuoteGenerator.get_symbol_sl_value(st.symbol.name, st.type)
st.mt_profit = Decimal(randint(1000, 100000) / 100)
st.save()
result:
test fails from different reasons.
I know it's lame "proof", but what else I can do? Pls try to disconnect
receiver in test (and maybe from another app).
Regards,
Mike
> Hi,
>
> I've tried to reproduce your issue but couldn't manage to get the
results you're describing.
>
> I used an empty `Foo` model (no fields except for the auto-generated
`id` one) and the following code:
> {{{#!python
> from django.db.models.signals import pre_save
> from django.dispatch import receiver
>
> from bug22657.models import Foo
>
> @receiver(pre_save)
> def callback(sender, **kwargs):
> print('Hello!')
>
> Foo.objects.create() # Prints "Hello"
> pre_save.disconnect(callback)
> Foo.objects.create() # Prints nothing
> }}}
>
> I've tried both `master` and the 1.6 branch and I get the same result in
both cases.
>
>
> Could you show us a piece of code that demonstrates the issue (and
reopen this ticket when you do so)?
>
> Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/22657#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/080.2f81ba3f96b1a0c4455db3c009bc9151%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.