Bug 125307 - PyUno wrongly converts Tuples of Strings
Summary: PyUno wrongly converts Tuples of Strings
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
5.2 all versions
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:6.4.0
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2019-05-15 12:44 UTC by Thomas Viehmann
Modified: 2022-11-25 03:43 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Viehmann 2019-05-15 12:44:03 UTC
Description:
Some uno functions, e.g. XPropertySet.setPropertyValue, accept arguments that can be of type Any("[]String").

Calling such a method with a tuple of strings (which would correspond to what's returned by getProperty) gives "inappropriate property value".

What appears to happen (from debugging with  PYSCRIPT_LOG_LEVEL=DEBUG PYUNO_LOGLEVEL=ARGS ) is that the tuple of strings get's converted into a Any of type []Any with each element of the list being an Any of type String.

Manually calling with

uno.invoke(..., "setPropertyValue", ("myprop", uno.Any("[]String", mytupleofstr)))

works, as described in

https://forum.openoffice.org/en/forum/viewtopic.php?t=56460

Steps to Reproduce:
Create a property of type []String in a python extension.
Try to read -> works, gives tuple of Strings.
Try to write -> doesn't work, uno.invoke works.

Actual Results:
try     py->uno[0x561181e85c80].setPropertyValue((string)"lstFoo", ([]any){ (any){ (string)"Apples" }, (any){ (string)"Bananas" }, (any){ (string)"Oranges" }, (any){ (string)"Grapes" } })
except  py->uno[0x561181e85c80].setPropertyValue = (com.sun.star.lang.IllegalArgumentException){ (com.sun.star.uno.RuntimeException){ (com.sun.star.uno.Exception){ Message = (string)"configmgr inappropriate property value", Context = (com.sun.star.uno.XInterface)0x56117709f6e0 } }, ArgumentPosition = (short)0x-1 }

Expected Results:
Conversion being to Any("[]String", ...).


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Stephan Bergmann 2019-05-16 07:53:24 UTC
see the mailing list thread starting at <https://lists.freedesktop.org/archives/libreoffice/2019-May/082763.html> "Converting Python Tuples / Lists into Any in PyUNO"
Comment 3 Thomas Viehmann 2019-05-18 05:58:44 UTC
Thanks Oliver! Those are great resources! (And I do sometimes look at the grammalecte plugin for inspiration of how PyUNO works, too)

So slide 18 (Elimination of explicit Any) is very close to my case. The implicit conversion to any here would be not to "string[]" as I would expect from the example, but to any[].

Maybe you or Matthew have an opinion on whether that's intentional or maybe less so?
Comment 4 Olivier R. 2019-05-26 06:37:15 UTC
Actually, I haven’t tried these new syntaxes for compatibility issues with older versions of LibreOffice. But as I dropped support for LOs < 5.3 recently, I will try that when I have the courage to dig in my code.

But I’m not familiar at all with LibreOffice internals, I have no opinion on your issue. I’m even surprised that my plugin could be inspirative, as I often feel more like I’m struggling with the LO API than really using it.
Comment 5 Thomas Viehmann 2019-09-19 12:18:18 UTC
So there is a brief discussion here:
https://lists.freedesktop.org/archives/libreoffice/2019-May/082782.html
(I didn't do the research mentioned there, though)

When we shy away from changing the auto-conversion, a partial mitigation might be to allow Any arguments to be passed to methods.
This would still have us doing the Any conversion explicitly, but we would not have to resort to uno.invoke, giving a 50% more pythonic feel to it.
Comment 6 Commit Notification 2019-09-19 18:00:44 UTC
Bjoern Michaelsen committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1cd495900883d1677670787669908535cd33babe

tdf#125307: move range properties check to own test

It will be available in 6.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Xisco Faulí 2019-12-03 10:56:45 UTC
A polite ping to Thomas Viehmann:
Is this bug fixed? if so, could you please close it as RESOLVED FIXED ?
Otherwise, Could you please explain what's missing?
Thanks
Comment 8 Thomas Viehmann 2019-12-03 11:27:17 UTC
This issue continues to exist. The problem is that it is potentially backwards compatibility-breaking to fix it (see the mailing list discussion).
Comment 9 Thomas Viehmann 2020-11-24 15:04:24 UTC
This is another instance:
https://ask.libreoffice.org/en/question/251641/pyuno-illegalargumentexception/
Comment 10 QA Administrators 2022-11-25 03:43:18 UTC
Dear Thomas Viehmann,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug