Bug 161331 - XInteractionRequest.getRequest crashes in XInteractionHandler callback in Python
Summary: XInteractionRequest.getRequest crashes in XInteractionHandler callback in Python
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
24.2.3.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-29 22:54 UTC by Ritobroto Mukherjee
Modified: 2024-09-20 15:21 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Minimal python example for the issue (1.72 KB, text/x-python)
2024-05-29 22:56 UTC, Ritobroto Mukherjee
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ritobroto Mukherjee 2024-05-29 22:54:58 UTC
Description:
When accessing the request object of the XInteractionRequest parameter in an XInteractionHandler from Python, the Python interpreter crashes with the error: "Fatal Python error: a function returned a result with an error set". 
The function works normally when called from Java however.

This bug was encountered while working on porting the PasswordContainer tests from Java to Python (https://gerrit.libreoffice.org/c/core/+/165038). A shorter sample is attached to the bug report as well, and can be run with `./instdir/program/python sample.py` via LibreOffice's internal python.

I attempted to debug the problem with gdb, but due to my very limited knowledge of Python UNO bindings, identifying the exact cause was challenging.
A shot-in-the-dark guess would be that since the result value MasterPasswordRequest is an exception type, returned through an Any object, the marshalling code that converts this value from C++ to Python might be causing the issue.

Steps to Reproduce:
1. Using the LibreOffice internal python, run the attached sample.py script.

Actual Results:
The python interpreter crashes with "Fatal Python error: a function returned a result with an error set"

Expected Results:
Not crash, and return a valid MasterPasswordRequest object.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version: 24.8.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 4c5485ef6826b5b2483df869056aac4499aff229
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Ritobroto Mukherjee 2024-05-29 22:56:05 UTC
Created attachment 194442 [details]
Minimal python example for the issue
Comment 2 Hossein 2024-07-02 14:32:54 UTC
Confirming on Linux with the latest LO 25.2 dev master:

Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 6a0d4d45d9e5933028f437ebd6756946a127e4a4
CPU threads: 12; OS: Linux 6.2; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

Note that after this error, I have to invoke: "killall soffice.bin":

$ instdir/program/python sample.py 
warn:io.connector:183249:183249:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno8272576145240759": 10
True
warn:pyuno.runtime:183249:183249:pyuno/source/module/pyuno_runtime.cxx:951: Python exception: <class 'SystemError'>: <PyUNO_callable object at 0x7fa2a32bf2d0> returned a result with an error set, traceback follows
  File "sample.py", line 35, in handle
    req = request.getRequest()  # This seems to not work!

 at /libreoffice/core/pyuno/source/module/pyuno_runtime.cxx:950
Traceback (most recent call last):
  File "sample.py", line 23, in main
    container.addPersistent(URL, USERNAME, PASSWORDS, master_handler)
uno.com.sun.star.uno.RuntimeException: <class 'SystemError'>: <PyUNO_callable object at 0x7fa2a32bf2d0> returned a result with an error set, traceback follows
  File "sample.py", line 35, in handle
    req = request.getRequest()  # This seems to not work!

 at /libreoffice/core/pyuno/source/module/pyuno_runtime.cxx:950

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sample.py", line 57, in <module>
    main()
  File "sample.py", line 26, in main
    print(e.with_traceback())
TypeError: com.sun.star.uno.RuntimeException.with_traceback() takes exactly one argument (0 given)
warn:binaryurp:183285:183304:binaryurp/source/bridge.cxx:840: undisposed bridge "" in state 2, potential deadlock ahead
Comment 3 Hossein 2024-07-02 14:37:54 UTC
The problem also happens on Windows, but with slightly different error message:

$ instdir/program/python sample.py
C:\cygwin64\home\user\lode\dev\core\instdir\program\officehelper.py:94: DeprecationWarning: invalid escape sequence \P
  """Bootstrap PyUNO Runtime.
warn:io.connector:18708:10072:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno808075796421522": 1
warn:io.connector:18708:10072:io/source/connector/connector.cxx:93: Connector : couldn't connect to pipe "uno808075796421522": 1
True
Fatal Python error: _Py_CheckFunctionResult: a function returned a result with an error set
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\cygwin64\home\user\lode\dev\core\instdir\program\uno.py", line 513, in _uno_struct__setattr__
    return setattr(self.__dict__["value"], name, value)
AttributeError: args

The above exception was the direct cause of the following exception:

SystemError: <PyUNO_callable object at 0x000002AD96C748B0> returned a result with an error set

Current thread 0x00002758 (most recent call first):
  File "C:\cygwin64\home\user\lode\dev\core\sample.py", line 35 in handle
  File "C:\cygwin64\home\user\lode\dev\core\sample.py", line 23 in main
  File "C:\cygwin64\home\user\lode\dev\core\sample.py", line 57 in <module>
Comment 4 Hossein 2024-09-19 18:11:04 UTC
Hello Xisco,

This bug is filed after porting a test from Java to Python showed some issues with the test execution:

tdf#97362 Rewrite PasswordContainer tests in python
https://gerrit.libreoffice.org/c/core/+/165038
Comment 5 Xisco Faulí 2024-09-20 12:18:18 UTC
(In reply to Hossein from comment #4)
> Hello Xisco,
> 
> This bug is filed after porting a test from Java to Python showed some
> issues with the test execution:
> 
> tdf#97362 Rewrite PasswordContainer tests in python
> https://gerrit.libreoffice.org/c/core/+/165038

Hi Hossein,
I downloaded https://gerrit.libreoffice.org/c/core/+/165038 and it doesn't crash for me when calling make PythonTest_svl_python
Comment 6 Ritobroto Mukherjee 2024-09-20 15:21:53 UTC
(In reply to Xisco Faulí from comment #5)
> Hi Hossein,
> I downloaded https://gerrit.libreoffice.org/c/core/+/165038 and it doesn't
> crash for me when calling make PythonTest_svl_python

Hello Mr. Xisco,

The failing test case is actually disabled in that patch. Please rename the function __disabled__test_02 to test_02, as the test runner only looks for cases starting with 'test'.

Additionally, the attached minimal sample in this bug report can be used too, since it's directly derived from that test case.