[ 
https://issues.apache.org/jira/browse/PROTON-2712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17713235#comment-17713235
 ] 

Jiri Daněk commented on PROTON-2712:
------------------------------------

Using https://github.com/rh-messaging/cli-proton-python to print {{user_id}} on 
a Message

{noformat}
% .venv/bin/python -c 'import proton; print(proton.VERSION)'
(0, 36, 0)

% .venv/bin/python -m cli_proton_python.sender --log-msgs=dict 
{'address': None, 'annotations': {}, 'content': None, 'content_encoding': 
'None', 'content_type': 'text/plain', 'correlation_id': None, 'creation_time': 
0.000000, 'delivery_count': 0, 'durable': False, 'expiration': 0, 
'first_acquirer': False, 'group_id': None, 'group_sequence': 0, 'id': None, 
'inferred': False, 'instructions': None, 'priority': 4, 'properties': {}, 
'reply_to': None, 'reply_to_group_id': None, 'subject': None, 'ttl': 0, 
'user_id': ''}
{noformat}

{noformat}
% python3 -c 'import proton; print(proton.VERSION)'
(0, 39, 0)

% python3 -m cli_proton_python.sender --log-msgs=dict
<frozen runpy>:128: RuntimeWarning: 'cli_proton_python.sender' found in 
sys.modules after import of package 'cli_proton_python', but prior to execution 
of 'cli_proton_python.sender'; this may result in unpredictable behaviour
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/sender.py", 
line 614, in <module>
    main()
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/sender.py", 
line 607, in main
    container.run()
  File "/home/jdanek/.local/lib/python3.11/site-packages/proton/_reactor.py", 
line 196, in run
    while self.process():
          ^^^^^^^^^^^^^^
  File "/home/jdanek/.local/lib/python3.11/site-packages/proton/_reactor.py", 
line 259, in process
    event.dispatch(handler)
  File "/home/jdanek/.local/lib/python3.11/site-packages/proton/_events.py", 
line 159, in dispatch
    _dispatch(handler, type.method, self)
  File "/home/jdanek/.local/lib/python3.11/site-packages/proton/_events.py", 
line 130, in _dispatch
    m(*args)
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/sender.py", 
line 393, in on_timer_task
    self.send_message()
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/sender.py", 
line 263, in send_message
    self.print_message(self.msg)
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/coreclient.py",
 line 200, in print_message
    utils.print_message(message, self.opts.log_msgs)
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/utils.py", 
line 110, in print_message
    print(formatter.Formatter(msg).print_message_as_dict())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/formatter.py",
 line 203, in print_message_as_dict
    int_result += "'%s': %s, " % (k, Formatter.format_object(int_value))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/formatter.py",
 line 169, in format_object
    return Formatter.format_string(in_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/formatter.py",
 line 144, in format_string
    int_res = "'%s'" % (Formatter.quote_string_escape(in_data))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File 
"/home/jdanek/repos/testing/cli/cli-proton-python/cli_proton_python/formatter.py",
 line 299, in quote_string_escape
    return in_data.replace("'", "\\'")
           ^^^^^^^^^^^^^^^
AttributeError: 'memoryview' object has no attribute 'replace'
{noformat}

When I inspect the {{message}} by running

{code}
print([f"{k}: {getattr(message,k)}" for k in dir(message)])
{code}

I get

{noformat}
[...]
'address: None',
'annotation_dict: AnnotationDict({})',
'annotations: AnnotationDict({})',
'body: None',
'clear: <bound method Message.clear of Message(priority=4)>',
'content_encoding: None',
'content_type: text/plain',
'correlation_id: None',
'creation_time: 0.0',
'decode: <bound method Message.decode of Message(priority=4)>',
'delivery_count: 0',
'durable: False',
'encode: <bound method Message.encode of Message(priority=4)>',
'expiry_time: 0.0',
'first_acquirer: False', 'group_id: None', 'group_sequence: 0',
'id: None',
'inferred: False',
'instruction_dict: None',
'instructions: None',
'priority: 4',
'properties: {}',
'recv: <bound method Message.recv of Message(priority=4)>',
'reply_to: None',
'reply_to_group_id: None',
'send: <bound method Message.send of Message(priority=4)>',
'subject: None',
'ttl: 0.0',
'user_id: <memory at 0x7f431e6a4040>']
{noformat}

whereas with prior versions of python-qpid-proton, I'd get

{noformat}
"user_id: b''"]
{noformat}

> [Python] Inconsistencies in binding type mappings
> -------------------------------------------------
>
>                 Key: PROTON-2712
>                 URL: https://issues.apache.org/jira/browse/PROTON-2712
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: python-binding
>    Affects Versions: proton-c-0.39.0
>            Reporter: Andrew Stitcher
>            Assignee: Andrew Stitcher
>            Priority: Major
>             Fix For: proton-c-0.39.0
>
>
> There were some inconsistencies and infelicities in the new cffi API bindings 
> type mappings between python and C types



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to