Bug 151455 - SQLError Event fails with Python
Summary: SQLError Event fails with Python
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
7.4.1.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-10 15:19 UTC by Andreas Säger
Modified: 2023-02-21 09:06 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Database document with Basic and Python code. (25.37 KB, application/vnd.oasis.opendocument.database)
2022-10-10 15:21 UTC, Andreas Säger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Säger 2022-10-10 15:19:58 UTC
Description:
The attached database contains a HSQL table with a unique index on a (case-insensitive) text field and an integer primary key.
One form triggers a Basic routine on index violation. The macro analyses the error object and pops up a user-defined error message.
The other form tries to do the same with Python code. However, the Python bridge complains about the error object when the following line is about to be executed:
s1 = er.Message
where er is ev.Source.Reason and ev.Source is an c.s.s.sdb.SQLErrorEvent

Steps to Reproduce:
1. Open odb document and TBL_Basic form.
2. Add/edit some record with duplicate name or ID.
3. You get a user-defined error message.
4. Do the same with form TBL_Python

Actual Results:
With the Python macro you get a runtime error because Python can't swallow ev.Source.Reason
A Scripting Framework error occurred while running the Python script vnd.sun.star.script:SQL_Error.py$SQLError?language=Python&location=document.

Message: <class 'ImportError'>: No module named 'apso_utils' (or 'apso_utils.msgbox' is unknown)
  File "/opt/libreoffice7.2/program/pythonscript.py", line 1057, in getScript
    mod = self.provCtx.getModuleByUrl( fileUri )
  File "/opt/libreoffice7.2/program/pythonscript.py", line 494, in getModuleByUrl
    exec(code, entry.module.__dict__)
  File "vnd.sun.star.tdoc:/55308760/Scripts/python/SQL_Error.py", line 3, in <module>
  File "/opt/libreoffice7.2/program/uno.py", line 423, in _uno_import
    raise uno_import_exc
  File "/opt/libreoffice7.2/program/uno.py", line 346, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)


Expected Results:
Should work with Python as well


Reproducible: Always


User Profile Reset: No



Additional Info:
none
Comment 1 Andreas Säger 2022-10-10 15:21:13 UTC
Created attachment 182949 [details]
Database document with Basic and Python code.
Comment 2 Alex Thurgood 2022-10-11 08:34:46 UTC
@Andreas : does this require the APSO extension to be installed in order to test?
Comment 3 Alex Thurgood 2022-10-11 08:40:26 UTC
The error I see with the Python script form when changing ID from '1' to '0':

com.sun.star.uno.RuntimeException: Error during invoking function SQLError in module vnd.sun.star.tdoc:/12864377288/Scripts/python/SQL_Error.py (<class 'SystemError'>: <built-in function getattr> returned a result with an error set
  File "/Applications/LO7412Arm.app/Contents/Resources/pythonscript.py", line 915, in invoke
    ret = self.func( *args )
  File "vnd.sun.star.tdoc:/12864377288/Scripts/python/SQL_Error.py", line 10, in SQLError
  File "/Applications/LO7412Arm.app/Contents/Resources/uno.py", line 504, in _uno_struct__getattr__
    return getattr(self.__dict__["value"], name)
)



This is on macOS LO aarch64, M1 silicon, Monterey 12.6 (Macbook Pro).
Comment 4 Alex Thurgood 2022-10-11 08:46:42 UTC
FWIW, I get a systematic crash and recovery dialog with 

Version: 7.4.1.2 / LibreOffice Community
Build ID: 3c58a8f3a960df8bc8fd77b461821e42c061c5f0
CPU threads: 8; OS: Mac OS X 12.6; UI render: default; VCL: osx
Locale: fr-FR (fr_FR.UTF-8); UI: fr-FR
Calc: threaded

when triggering the Basic script, more particularly, when clicking on "OK" of the message box. Probably worth a separate bug report.
Comment 5 Alex Thurgood 2022-10-11 10:30:36 UTC
(In reply to Alex Thurgood from comment #4)


> when triggering the Basic script, more particularly, when clicking on "OK"
> of the message box. Probably worth a separate bug report.

Ironically, when running this against LODev daily in a lldb session, the crash doesn't occur. Remove the debug tracing, and the crash occurs systematically.
Comment 6 Andreas Säger 2022-10-11 18:41:50 UTC
(In reply to Alex Thurgood from comment #2)
> @Andreas : does this require the APSO extension to be installed in order to
> test?

It would require APSO if it reached the point where it shows a user defined msgbox.
Comment 7 Buovjaga 2023-02-21 09:06:46 UTC
(In reply to Alex Thurgood from comment #3)
> The error I see with the Python script form when changing ID from '1' to '0':
> 
> com.sun.star.uno.RuntimeException: Error during invoking function SQLError
> in module vnd.sun.star.tdoc:/12864377288/Scripts/python/SQL_Error.py (<class
> 'SystemError'>: <built-in function getattr> returned a result with an error
> set
>   File "/Applications/LO7412Arm.app/Contents/Resources/pythonscript.py",
> line 915, in invoke
>     ret = self.func( *args )
>   File "vnd.sun.star.tdoc:/12864377288/Scripts/python/SQL_Error.py", line
> 10, in SQLError
>   File "/Applications/LO7412Arm.app/Contents/Resources/uno.py", line 504, in
> _uno_struct__getattr__
>     return getattr(self.__dict__["value"], name)
> )

I get the same in

Arch Linux 64-bit, X11
Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 0bcce236059ae68c6dcc7bce8ceaec5d39c28f1c
CPU threads: 8; OS: Linux 6.1; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Built on 21 February 2023

with APSO installed.

I don't know why this was still unconfirmed.