Bug 151932 - GalleryItem ( XGalleryItem ) wipes some of its properties as soon as it is returned from a function.
Summary: GalleryItem ( XGalleryItem ) wipes some of its properties as soon as it is re...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.3.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-06 13:29 UTC by vibrationoflife
Modified: 2025-11-27 11:29 UTC (History)
1 user (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 vibrationoflife 2022-11-06 13:29:19 UTC
GalleryItem ( XGalleryItem ) wipes some of its properties as soon as it is returned from a funciton.

This bug is found in Python

When a GalleryItem is passed from a function it looses Drawing, Graphic, etc, properties.

Pseudo code for illustration

> import sys
> 
> def find_gallery_item(gallery_name: str, name: str) -> XGalleryItem:
>     gallery = get_gallery(gallery_name) # XGalleryTheme
>     num_pics = gallery.getCount()
> 
>     result = None
>     for i in range(num_pics):
>         item = gallery.getByIndex(i)
>         # run code to find item.
>         result = item
>         break
> 
>     # sys.getrefcount() adds a refcount so sys.getrefcount() - 1
>     # Reference count for result.Drawing is 0
>     print("result.Drawing ref count:", sys.getrefcount(result.Drawing) - 1)
>     # this means as soon as result is return from this function then 
>     #python garbage collector deletes result.Drawing
> 
>     # this next line report as expected. result.Drawing is XDrawing instance
>     report_gallery_item(result)
>     return result
> 
>     def report_gallery_item(item: XGalleryItem) -> None:
>         if item is None:
>             print("Gallery item is null")
>             return
> 
>         print("Gallery item information:")
>         url = str(mProps.Props.get(item, "URL"))
>         path = mFileIo.FileIO.uri_to_path(uri_fnm=url, ensure_absolute=False)
>         print(f'  URL: "{url}"')
>         print(f'  Fnm: "{Path(Gallery.gallery_dir, mFileIo.FileIO.get_fnm(path))}"')
>         print(f"  Path: {path}")
> 
>         print(f'  Title: "{mProps.Props.get(item, "Title")}"')
>         item_int_type = int(mProps.Props.get(item, "GalleryItemType"))
>         print(f"  Type: {cls.get_item_type_str(GalleryItemTypeEnum(item_int_type))}")
> 
> item = find_gallery_item(gallery_name="Shapes", name="Sun")
> 
> report_gallery_item(item) # at this point item.Drawing is None

I have documented this in some detail on Ask.
https://ask.libreoffice.org/t/libreoffice-wiping-object-properties-issue-with-gallerythemeprovider/83182
Comment 1 vibrationoflife 2022-11-06 13:32:22 UTC
I was converting Java to Python when I came accross this bug.
Clearly the Java code does not expect this bug.

See:
https://flywire.github.io/lo-p/14-Animation.html#3-another-way-to-access-the-gallery
Comment 2 vibrationoflife 2022-11-06 13:43:20 UTC
Pseudo code Indentation correction.

> import sys
> 
> def find_gallery_item(gallery_name: str, name: str) -> XGalleryItem:
>     gallery = get_gallery(gallery_name) # XGalleryTheme
>     num_pics = gallery.getCount()
>
>     result = None
>     for i in range(num_pics):
>         item = gallery.getByIndex(i)
>         # run code to find item.
>         result = item
>         break
> 
>     # sys.getrefcount() adds a refcount so sys.getrefcount() - 1
>     # Reference count for result.Drawing is 0
>     print("result.Drawing ref count:", sys.getrefcount(result.Drawing) - 1)
>     # this means as soon as result is return from this function then 
>     #python garbage collector deletes result.Drawing
> 
>     # this next line report as expected. result.Drawing is XDrawing instance
>     report_gallery_item(result)
>     return result
> 
> def report_gallery_item(item: XGalleryItem) -> None:
>     if item is None:
>         print("Gallery item is null")
>         return
> 
>     url = str(mProps.Props.get(item, "URL"))
>     print("Gallery item information:")
>     path = mFileIo.FileIO.uri_to_path(uri_fnm=url, ensure_absolute=False)
>     print(f'  URL: "{url}"')
>     print(f'  Fnm: "{Path(Gallery.gallery_dir, mFileIo.FileIO.get_fnm(path))}"')
>     print(f"  Path: {path}")
> 
>     print(f'  Title: "{mProps.Props.get(item, "Title")}"')
>     item_int_type = int(mProps.Props.get(item, "GalleryItemType"))
>     print(f"  Type: {cls.get_item_type_str(GalleryItemTypeEnum(item_int_type))}")
>
> item = find_gallery_item(gallery_name="Shapes", name="Sun")
>
> report_gallery_item(item) # at this point item.Drawing is None
Comment 3 Buovjaga 2023-03-03 14:53:16 UTC
Do you mean this pseudo code will not run? If not, then how can QA quickly test this?
Comment 4 vibrationoflife 2023-04-22 15:31:20 UTC
I created a code sample to run and show the issue in the OooDev project.

https://github.com/Amourspirit/python_ooo_dev_tools/tree/main/tests/samples/gallery_issue


For install instructons of OooDev project set the Dev Docs.

https://python-ooo-dev-tools.readthedocs.io/en/develop/dev_docs/dev_notes.html
Comment 5 QA Administrators 2025-11-27 11:29:26 UTC
Dear vibrationoflife,

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