from urllib.parse import parse_qs
from channels import Group
from channels.sessions import channel_session


@channel_session
def ws_add(message):
    message.reply_channel.send({"accept": True})
    qs = parse_qs(message['query_string'])
    workflow_pk = qs['workflow_pk'][0]
    message.channel_session['workflow_pk'] = workflow_pk
    Group("workflow-{}".format(workflow_pk)).add(message.reply_channel)


@channel_session
def ws_disconnect(message):
    workflow_pk = message.channel_session['workflow_pk']
    Group("workflow-{}".format(workflow_pk)).discard(message.reply_channel)

from urllib.parse import parse_qs
from channels import Group
from channels.sessions import channel_session


@channel_session
def ws_add(message):
    message.reply_channel.send({"accept": True})
    qs = parse_qs(message['query_string'])
    workflow_pk = qs[b'workflow_pk'][0].decode('utf-8')
    message.channel_session['workflow_pk'] = workflow_pk
    Group("workflow-{}".format(workflow_pk)).add(message.reply_channel)


@channel_session
def ws_disconnect(message):
    workflow_pk = message.channel_session['workflow_pk']
    Group("workflow-{}".format(workflow_pk)).discard(message.reply_channel)

Fix query string problem of comparing byte strings and unicode strings in py3
Fix query string problem of comparing byte strings and unicode strings in py3

  from urllib.parse import parse_qs
  from channels import Group
  from channels.sessions import channel_session
  
  
  @channel_session
  def ws_add(message):
      message.reply_channel.send({"accept": True})
      qs = parse_qs(message['query_string'])
-     workflow_pk = qs['workflow_pk'][0]
+     workflow_pk = qs[b'workflow_pk'][0].decode('utf-8')
      message.channel_session['workflow_pk'] = workflow_pk
      Group("workflow-{}".format(workflow_pk)).add(message.reply_channel)
  
  
  @channel_session
  def ws_disconnect(message):
      workflow_pk = message.channel_session['workflow_pk']
      Group("workflow-{}".format(workflow_pk)).discard(message.reply_channel)
  
Fix query string problem of comparing byte strings and unicode strings in py3
## Code Before:
from urllib.parse import parse_qs
from channels import Group
from channels.sessions import channel_session


@channel_session
def ws_add(message):
    message.reply_channel.send({"accept": True})
    qs = parse_qs(message['query_string'])
    workflow_pk = qs['workflow_pk'][0]
    message.channel_session['workflow_pk'] = workflow_pk
    Group("workflow-{}".format(workflow_pk)).add(message.reply_channel)


@channel_session
def ws_disconnect(message):
    workflow_pk = message.channel_session['workflow_pk']
    Group("workflow-{}".format(workflow_pk)).discard(message.reply_channel)

## Instruction:
Fix query string problem of comparing byte strings and unicode strings in py3
## Code After:
from urllib.parse import parse_qs
from channels import Group
from channels.sessions import channel_session


@channel_session
def ws_add(message):
    message.reply_channel.send({"accept": True})
    qs = parse_qs(message['query_string'])
    workflow_pk = qs[b'workflow_pk'][0].decode('utf-8')
    message.channel_session['workflow_pk'] = workflow_pk
    Group("workflow-{}".format(workflow_pk)).add(message.reply_channel)


@channel_session
def ws_disconnect(message):
    workflow_pk = message.channel_session['workflow_pk']
    Group("workflow-{}".format(workflow_pk)).discard(message.reply_channel)
