Difficulty with celery: the function object does not have the 'delay' property

I recently started developing software and was successful in bending celery as I wanted.

I successfully used it to send emails and just tried to use almost exactly the same code (after restarting all processes, etc.) to send sms via Twilio.

However, I keep getting the following problem:

File "/Users/Rob/Dropbox/Python/secTrial/views.py", line 115, in send_sms send_sms.delay(recipients, form.text.data) AttributeError: 'function' object has no attribute 'delay' 

My code is as follows:

 @celery.task def send_email(subject, sender, recipients, text_body): msg = Message(subject, sender=sender) for email in recipients: msg.add_recipient(email) msg.body = text_body mail.send(msg) @celery.task def send_sms(recipients, text_body): for number in recipients: print number num = '+61' + str(number) print num msg = text_body + 'this message to' + num client.messages.create(to=num, from_="+14804054823", body=msg) 

send_email.delay when called from my view.py works fine, however send_sms.delay fails every time with the above error.

Any troubleshooting help is appreciated.

- in accordance with the request:

 @app.route('/send_mail', methods=['GET', 'POST']) @roles_accepted('Admin') def send_mail(): form = SendMailForm(request.form) if request.method == 'POST': if form.validate_on_submit(): emails = db.session.query(User.email).all() list_emails = list(zip(*emails)[0]) send_email.delay('Subject', 'sender@example.com', list_emails, form.text.data) return render_template('send_generic.html', form=form) @app.route('/send_sms', methods=['GET', 'POST']) @roles_accepted('Admin') def send_sms(): form = SendMailForm(request.form) if request.method == 'POST': if form.validate_on_submit(): recipients = db.session.query(User.mobile).all() list_recipients = filter(None, list(zip(*recipients)[0])) send_sms.delay(list_recipients, form.text.data) return render_template('send_generic.html', form=form, send_sms=send_sms) 

The send_sms celery function is decorated as a registered task:

 (env)RP:secTrial Rob$ celery inspect registered -> celery@RP.local: OK * app.send_email * app.send_security_email * app.send_sms 

and for config, I just use guest: rabbitmq

 CELERY_BROKER_URL = 'amqp://guest@localhost//' CELERY_RESULT_BACKEND = 'amqp://guest@localhost//' 
+8
python flask flask-security celery
source share
1 answer

The name of the form send_sms conflicts with the name of the celery task. The name send_sms refers to the view, not the task, when it is used in the module that contains the view.

Use a different name to avoid overwriting.

+12
source share

All Articles