Skip to content

F-strings in BO MessageMap causes error #2

@gabriel-ing

Description

@gabriel-ing

Description

When defining a Business Operation, I am trying to use an f-string in a message map to make it easier to reference the package name of my message class. However when linking to IRIS using InterSystems PyProd I run into errors.

Code

from intersystems_pyprod import BusinessOperation

iris_package_name = "sample.packagename"

class TestBusinessOperation(BusinessOperation):
    MessageMap = {
        f"{iris_package_name}.MyMessage": "on_my_message"
    }

    def on_my_message(self, message):
        IRISLog.Info("Recieved MyMessage")

Error

Gives the following error trace when running intersystems_pyprod test.py

Traceback (most recent call last):
  File "/home/irisowner/.pyprod_env/bin/intersystems_pyprod", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/irisowner/.pyprod_env/lib/python3.12/site-packages/intersystems_pyprod/_parser.py", line 983, in main
    generate_os_classes(
  File "/home/irisowner/.pyprod_env/lib/python3.12/site-packages/intersystems_pyprod/_parser.py", line 542, in generate_os_classes
    props_lines, settings_list, message_map_methods = extract_props_and_settings(node, real_path)
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/irisowner/.pyprod_env/lib/python3.12/site-packages/intersystems_pyprod/_parser.py", line 445, in extract_props_and_settings
    k.value: v.value for k, v in zip(call_node.keys, call_node.values)
    ^^^^^^^
AttributeError: 'JoinedStr' object has no attribute 'value'. Did you mean: 'values'?

Workaround

Use a plain string literal for for the package name instead of an f‑string:

from intersystems_pyprod import BusinessOperation

iris_package_name = "sample.packagename"

class TestBusinessOperation(BusinessOperation):
    MessageMap = {
        "sample.packagename.MyMessage": "on_my_message"
    }

    def on_my_message(self, message):
        IRISLog.Info("Recieved MyMessage")

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions