You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An unexpected behaviour occurs when trying to send a message to the group via the Redis channel when called from the celery shared task in the except block or any subsequent code if the exception occurs.
OS: macOS: 13.0.1 (22A400)
Browser: Google Chrome (Version 108.0.5359.98 (Official Build) (arm64))
Server: Django Daphne ASGI Server
@shared_task(bind=True)defupload_to_sharepoint_task(self, user_id: str, document_type: str, upload_file: str, filename: str) ->None:
"""Uploads a file to SharePoint."""task_id=self.request.idtry:
upload_to_sharepoint(user_id, document_type, upload_file, filename)
print(f"Task {task_id} completed successfully.")
async_to_sync(get_channel_layer().group_send)(task_id, {
"type": "send_task_status",
"message": {'task_id': task_id, 'status': status, "error": error}
})
exceptExceptionase:
print(f"Task {task_id} failed to execute. Posting message to the group.")
async_to_sync(get_channel_layer().group_send)(task_id, {
"type": "send_task_status",
"message": {'task_id': task_id, 'status': status, "error": error}
})
print("Message send to the group.")
Expected Behaviour
When the exception is thrown, an error message is sent via channels to the subscribed group, and the client is notified.
Actual Behaviour
The problem is that when an exception is thrown, then both print messages are called; however, no message is sent to the group, and therefore client gets no notification. When no exception is thrown, then everything works as expected.
Logs
No logs are provided as the system acts like everything is alright.
Please also try and include, if you can:
Channels Configuration
Daphne and build the server of the React client. An issue occurred in the development environment.
importosfromchannels.authimportAuthMiddlewareStackfromchannels.routingimportProtocolTypeRouter, URLRouterfromdjango.core.asgiimportget_asgi_applicationfromchannels.security.websocketimportAllowedHostsOriginValidatoros.environ.setdefault('DJANGO_SETTINGS_MODULE', 'octo_manager.settings')
# Initialize Django ASGI application early to ensure the AppRegistry# is populated before importing code that may import ORM models.django_asgi_app=get_asgi_application()
importapi.routingapplication=ProtocolTypeRouter({
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(api.routing.websocket_urlpatterns))
),
})
The text was updated successfully, but these errors were encountered:
@carltongibson Is it necessary? It's not really about the SharePoint library that I am using; rather than that, if I trigger any exception and want to send a message about it, it just does nothing. Furthermore, the WebSocket from a client (fronted) remains open.
To reproduce the error, you need to trigger the error inside a Celery and in the except block or anywhere after the try-except statement and send a message to the group.
Anyway, suppose you insist on providing some running examples. What all sources do you need since we talk about the regular Django application and the minimal running sample does not bring any benefits?
@MichalKyjovsky A runnable reproduce is necessary yes. You're saying there's a bug. Without a reproduce that's hard to verify.
I'm afraid I don't have the time it would take to reconstruct the reproduce for your problem from the information you've given. You're seeing it: it's much easier for you to create a minimal sample project.
It's not really about the SharePoint library that I am using...
Exactly. So a minimal example excludes all that is not relevant. That way it's possible to see what the error is in Channels, if there is one, or in your project, which you may discover whilst working on the reproduce.
An unexpected behaviour occurs when trying to send a message to the group via the Redis channel when called from the celery shared task in the except block or any subsequent code if the exception occurs.
OS: macOS: 13.0.1 (22A400)
Browser: Google Chrome (Version 108.0.5359.98 (Official Build) (arm64))
Server: Django Daphne ASGI Server
pip freeze
I have the following celery shared task:
Expected Behaviour
When the exception is thrown, an error message is sent via channels to the subscribed group, and the client is notified.
Actual Behaviour
The problem is that when an exception is thrown, then both print messages are called; however, no message is sent to the group, and therefore client gets no notification. When no exception is thrown, then everything works as expected.
Logs
No logs are provided as the system acts like everything is alright.
Please also try and include, if you can:
Channels Configuration
Daphne and build the server of the React client. An issue occurred in the development environment.
settings.py :
asgi.py
The text was updated successfully, but these errors were encountered: