Created attachment 117348 [details] Presentation with a table shape com.sun.star.drawing.TableShape has a String attribute but trying to access it or check that it exists with hasattr(shape, "String")gives an error: uno.RuntimeException: illegal object given! I'm not sure if the table should have the String attribute but checking that the attribute exists shouldn't give an error in any case. To reproduce, start LibreOffice with: libreoffice "--accept=pipe,name=test;urp;StarOffice.Servicemanager" and execute the following python-uno code: import uno from pythonscript import ScriptContext localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver',localContext) client = resolver.resolve("uno:pipe,name=test;urp;StarOffice.ComponentContext") xscriptcontext = ScriptContext(client, None, None) doc = xscriptcontext .getDocument() slide = doc.DrawPages[0] for shape in slide: print(hasattr(shape, "String"))
(In reply to Ofir from comment #0) > and execute the following python-uno code: How do I do this?
Created attachment 117538 [details] Python script reproducing the error
Make sure you have the python-uno binding. On Ubuntu you can get them with sudo apt-get install libreoffice-script-provider-python Run LibreOffice with: libreoffice "--accept=pipe,name=test;urp;StarOffice.Servicemanager" Download the attached python script and run it with: python3 test.py
(In reply to Ofir from comment #3) > Make sure you have the python-uno binding. > On Ubuntu you can get them with > sudo apt-get install libreoffice-script-provider-python > > Run LibreOffice with: > libreoffice "--accept=pipe,name=test;urp;StarOffice.Servicemanager" > > Download the attached python script and run it with: > python3 test.py I get: Traceback (most recent call last): File "test.py", line 13, in <module> slide = doc.DrawPages[0] AttributeError: DrawPages
The python script expects LibreOffice 5.1. To test with LO < 5.0 and below use this: #!/usr/bin/python3 # -*- coding: utf-8 -*- import uno from pythonscript import ScriptContext localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver',localContext) client = resolver.resolve("uno:pipe,name=test;urp;StarOffice.ComponentContext") xscriptcontext = ScriptContext(client, None, None) doc = xscriptcontext .getDocument() ## new API in LibreOffice 5.1 #slide = doc.DrawPages[0] #for shape in slide: # print(hasattr(shape, "String")) slide = doc.DrawPages.getByIndex(0) for i in range(slide.Count): shape = slide.getByIndex(i) print(hasattr(shape, "String"))
Oh, sorry I forgot to mention I tested with 5.1: Ubuntu 15.04 64-bit Version: 5.1.0.0.alpha1+ Build ID: 902255645328efde34ddf62227c8278e8dd61ff0 TinderBox: Linux-rpm_deb-x86_64@70-TDF-dbg, Branch:master, Time: 2015-07-30_03:52:32 Locale: en-US (en_US.UTF-8)
Did you open the attached ODP in LibreOffice after starting it in server mode?
(In reply to Ofir from comment #7) > Did you open the attached ODP in LibreOffice after starting it in server > mode? No. You didn't mention that step. Now that I did, I get this after launching python3 test.py: Traceback (most recent call last): File "test.py", line 13, in <module> slide = doc.DrawPages[0] TypeError: 'pyuno' object is not subscriptable
You need to make sure you are using the LibreOffice 5.1 version of py-uno by setting the environment variables. On Ubuntu I'm using this: export PYTHONPATH=/usr/lib/python3.4/site-packages:/opt/libreofficedev5.1/program export URE_BOOTSTRAP="vnd.sun.star.pathname:/opt/libreofficedev5.1/program/fundamentalrc" Another option is to test the modified python script from Comment 5 that will work with previous version of LibreOffice.
Ok, I set the vars, adjusting to my 5.1 folder, but I still get the same error as in comment 8.
Created attachment 117561 [details] Python script that use the old python-uno syntax
You don't use the new python-uno API or you didn't open the ODP. Please try the python scripted I attached that can work with LibreOffice 5 and below.
Ok, now I got it with 5.1: Traceback (most recent call last): File "test.py", line 15, in <module> print(hasattr(shape, "String")) uno.RuntimeException: illegal object given! I had failed to do the exports in both terminal windows: the one where I launch LibO AND the second one where I launch the py. Ubuntu 15.04 64-bit Version: 5.1.0.0.alpha1+ Build ID: 902255645328efde34ddf62227c8278e8dd61ff0 TinderBox: Linux-rpm_deb-x86_64@70-TDF-dbg, Branch:master, Time: 2015-07-30_03:52:32 Locale: en-US (en_US.UTF-8)
** Please read this message in its entirety before responding ** 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 on a currently supported version of LibreOffice (5.1.5 or 5.2.1 https://www.libreoffice.org/download/ If the bug is present, please leave a comment that includes the version of LibreOffice and your operating system, and any changes you see in the bug behavior If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a short comment that includes your version of LibreOffice and Operating System 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) http://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: http://webchat.freenode.net/?channels=libreoffice-qa Thank you for helping us make LibreOffice even better for everyone! Warm Regards, QA Team MassPing-UntouchedBug-20160920
Still reproducible with: Version: 5.2.1.2 Build ID: 1:5.2.1~rc2-0ubuntu1~xenial0 CPU Threads: 1; OS Version: Linux 4.4; UI Render: default; Locale: en-US (en_US.UTF-8); Calc: group
** Please read this message in its entirety before responding ** 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 on a currently supported version of LibreOffice (5.4.1 or 5.3.6 https://www.libreoffice.org/download/ If the bug is present, please leave a comment that includes the version of LibreOffice and your operating system, and any changes you see in the bug behavior If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a short comment that includes your version of LibreOffice and Operating System 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) http://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: http://webchat.freenode.net/?channels=libreoffice-qa Thank you for helping us make LibreOffice even better for everyone! Warm Regards, QA Team MassPing-UntouchedBug-20170929
Still reproducible with LibreOffice 6.1.2.1
Since [1] (Python 3.2+), Python only tests for AttributeError in its hasattr(). Thus, returning other types of errors (as is done in our PyUno implementation [2]) would give wrong results. Still, it's not enough to just always return AttributeError from PyUNO_getattr: this will defeat the idea behind the Python change (see [3]). In this case, an interface is found that has the property (com.sun.star.text.XTextAppend), and its getter is attempted on the passed object, which is queried for that interface to do that. The query fails in IdlReflectionServiceImpl::mapToUno (more precisely, in extract() called there), and generic RuntimeException is thrown. It's unclear (to me) how to handle that here. [1] https://hg.python.org/cpython/rev/2de9d4457082/ [2] https://git.libreoffice.org/core/+/08c3c504644ee978c2ec75ba083765b6ffddf08c/pyuno/source/module/pyuno.cxx#1378 [3] https://stackoverflow.com/questions/35566680/pythons-hasattr-sometimes-returns-incorrect-results
Stephan, would you please take a look at this?
The problem is that SvxTableShape (aka OBJ_TABLE) doesn't implement css::text::XTextAppend (it just derives from SvxShape, see svx/source/unodraw/shapeimpl.hxx), so while ImplIntrospectionAccess::hasProperty (stoc/source/inspect/introspection.cxx) returns true for "String" (because css::text::XTextAppend -> css::text::XText -> css::text::XSimpleText -> css::text::XTextRange has get/setString methods), its ImplIntrospectionAccess::getPropertyValue counterpart ultimately fails because querying the SvxTableShape instance for XTextAppend fails. Fix at <https://gerrit.libreoffice.org/#/c/62739/> "tdf#92848: SvxTableShape doesn't implement css::text::XTextAppend".
(In reply to Ofir from comment #0) > com.sun.star.drawing.TableShape has a String attribute but trying to access > it or check that it exists with hasattr(shape, "String")gives an error: > uno.RuntimeException: illegal object given! Not sure what "com.sun.star.drawing.TableShape" is meant to be, but the relevant table shape object in the reproducer Python code doesn't actually support a String attribute, so hasattr(shape, "String") will now return False.
Stephan Bergmann committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/+/4bd701a306c8068911203f976145adc717f015d2%5E%21 tdf#92848: SvxTableShape doesn't implement css::text::XTextAppend It will be available in 6.2.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.