Uploaded image for project: 'AMQ Clients'
  1. AMQ Clients
  2. ENTMQCL-483

[python] Selectors fail with non-Unicode strings

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 2.1.0.GA
    • amqp-python-client
    • Release Notes
    • Hide
      The Selector option on Container.create_receiver() accepts a string. If the string is not supplied as Unicode (in Python 2, u"somestring"), any elements escaped with backslashes may not be processed correctly.

      Workaround: Users of Python 2 should use an explicit Unicode string in filter declarations to avoid the problem.
      Show
      The Selector option on Container.create_receiver() accepts a string. If the string is not supplied as Unicode (in Python 2, u"somestring"), any elements escaped with backslashes may not be processed correctly. Workaround: Users of Python 2 should use an explicit Unicode string in filter declarations to avoid the problem.
    • Documented as Known Issue
    • Hide

      Start ER16 A-MQ 7 broker, ER15 can be used too

      Run python aac5_receiver.py --timeout 2 --broker-url "admin:admin@127.0.0.1:61616/test_like_escape_syntax_true" --log-msgs dict --count 1024 --duration 1024 --recv-selector "a LIKE \'%4sm50jZM\\%\' ESCAPE \'\\\'"

      ERROR:root:Invalid filter
      Traceback (most recent call last):
        File "aac5_receiver.py", line 360, in <module>
          main()
        File "aac5_receiver.py", line 354, in main
          container.run()
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 133, in run
          while self.process(): pass
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 159, in process
          self._check_errors()
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 155, in _check_errors
          _compat.raise_(exc, value, tb)
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 4050, in dispatch
          ev.dispatch(self.handler)
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 3959, in dispatch
          result = dispatch(handler, type.method, self)
        File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 3839, in dispatch
          return handler.on_unhandled(method, *args)
        File "/home/jdanek/Work/repos/dtests/dtests/node_data/clients/python/Aac5CoreClient.py", line 268, in on_unhandled
          raise ClientException("Link error: %s ..." % self._evaluate_endpoint_error(event.link, "link"))
      Aac5CoreClient.ClientException: Link error: Invalid filter ...
      
      Show
      Start ER16 A-MQ 7 broker, ER15 can be used too Run python aac5_receiver.py --timeout 2 --broker-url "admin:admin@127.0.0.1:61616/test_like_escape_syntax_true" --log-msgs dict --count 1024 --duration 1024 --recv-selector "a LIKE \'%4sm50jZM\\%\' ESCAPE \'\\\'" ERROR:root:Invalid filter Traceback (most recent call last): File "aac5_receiver.py", line 360, in <module> main() File "aac5_receiver.py", line 354, in main container.run() File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 133, in run while self.process(): pass File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 159, in process self._check_errors() File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/reactor.py", line 155, in _check_errors _compat.raise_(exc, value, tb) File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 4050, in dispatch ev.dispatch(self.handler) File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 3959, in dispatch result = dispatch(handler, type.method, self) File "/home/jdanek/.virtualenvs/p2dtests/lib/python2.7/site-packages/proton/__init__.py", line 3839, in dispatch return handler.on_unhandled(method, *args) File "/home/jdanek/Work/repos/dtests/dtests/node_data/clients/python/Aac5CoreClient.py", line 268, in on_unhandled raise ClientException("Link error: %s ..." % self._evaluate_endpoint_error(event.link, "link")) Aac5CoreClient.ClientException: Link error: Invalid filter ...
    • Moraga, Noriega

      If I specify a selector with Python 2 byte string,

      link_opts = []
      ...
      link_opts.append(proton.reactor.Selector("""a LIKE \'%4sm50jZM\\%\' ESCAPE \'\\\'""")))
      ...
      event.container.create_receiver(self.url, options=self.link_opts, ...)
      

      Wireshark shows it is sent as vbin8,

      Filter (map of 1 element)
      		selector : apache.org:selector-filter:string (vbin8): 61204c494b4520272534736d35306a5a4d5c252720455343...
      

      and when this gets to proton-j in broker, it becomes type Binary. Broker calls .toString() on it, tries to parse that string as selector and fails.

      The problem is that backslashes are escaped as \x5c in the String representaion of Binary, so my original selector "a LIKE \'%4sm50jZM\\%\' ESCAPE \'\\\'" becomes "a LIKE '%4sm50jZM\x5c%' ESCAPE '\x5c'", which is invalid selector that the broker rejects.

      If I use unicode in proton.reactor.Selector(u"""a LIKE \'%4sm50jZM\\%\' ESCAPE \'\\\'"""), then it is sent as

      Filter (map of 1 element)
      		selector : apache.org:selector-filter:string (str8-utf8): a LIKE '%4sm50jZM\%' ESCAPE '\'
      

      and all works correctly.

      I am not sure if this is an issue or just something to document. Should the broker be more permissive, maybe, and deal with selector in vbin8?

              kvanderr@redhat.com Kim van der Riet
              jdanek@redhat.com Jiri Daněk
              Jiri Daněk Jiri Daněk
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - 3 hours
                  3h
                  Remaining:
                  Remaining Estimate - 3 hours
                  3h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified