Bug 126487 - id of objects changes on every access
Summary: id of objects changes on every access
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
6.2.5.2 release
Hardware: All All
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-20 13:33 UTC by Konstantin Kharlamov
Modified: 2022-07-21 04:10 UTC (History)
2 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 Konstantin Kharlamov 2019-07-20 13:33:58 UTC
When moving across document hierarchy, sometimes it's needed to determine whether 2 objects are the same thing *(not in terms of properties/values, but as in, really refer to the same thing)*. For example, when you have some cell1 and cell2, there's no need to waste energy comparing all properties with cell1 == cell2, when one can just do id(cell1) == id(cell2) (btw, the == operator doesn't work either).

But for some reason for every access to any UNO object the object id changes. It doesn't sound right even in terms of performance (like, why to create every time a different instance?).

# Steps to reproduce

1. Run python shell
2. In python shell execute the following commands

    >>> import uno
    >>> localContext = uno.getComponentContext()
    >>> list_of_same_objects = [localContext.ServiceManager for i in range(0,10)]
    >>> [id(obj) for obj in list_of_same_objects]
    [139769180615904, 139769180615928, 139769180615952, 139769180615976, 139769180616000, 139769180616024, 139769180616048, 139769180616072, 139769180616096, 139769180616120]

## Expected

The last command should've returned list of the same numbers.

## Actual

All numbers in the last command are different

# Additional information

See also: https://ask.libreoffice.org/en/question/201705/uno-determine-if-2-objects-refer-to-the-same-thing/
Comment 1 businessstepbystep 2019-07-21 10:12:28 UTC Comment hidden (spam)
Comment 2 Noel Grandin 2019-07-22 08:29:42 UTC
Those are different objects (in the python sense) which is why they return different id() values. 
There is no way to fix that, id() cannot be overridden.

However, it might be possible to make == work, by checking the underlying remote object identity, if that is exposed by the UNO bridge, I'm not sure.


Code pointers for anyone who is interested on working on this:

That would require changes to the code in /pyuno

I suspect we need the equivalent of m_oid from
   bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/JNI_proxy.java
implemented in the pyuno bridge.
Comment 3 Buovjaga 2020-04-17 15:34:47 UTC
NEW per comment 2
Comment 4 smdcitations 2020-07-20 04:59:35 UTC Comment hidden (spam)
Comment 5 QA Administrators 2022-07-21 03:33:44 UTC Comment hidden (obsolete)
Comment 6 Konstantin Kharlamov 2022-07-21 04:10:08 UTC
(In reply to QA Administrators from comment #5)
> Test to see if the bug is still present with the latest version of
> LibreOffice from https://www.libreoffice.org/download/

Still reproducible with LibreOffice 7.3.4.2 30(Build:2)