After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 641944 - Do not bind gobject_get_data() and gobject_set_data()
Do not bind gobject_get_data() and gobject_set_data()
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
3.3.x
Other All
: Normal minor
: GNOME 3.8
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-02-09 17:40 UTC by Steve Frécinaux
Modified: 2012-10-23 07:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Do not bind gobject_get_data() and gobject_set_data() (2.31 KB, patch)
2011-02-09 17:40 UTC, Steve Frécinaux
committed Details | Review
(broken) attempt to add them back in the metaclass (1.61 KB, patch)
2012-05-14 16:48 UTC, Martin Pitt
needs-work Details | Review

Description Steve Frécinaux 2011-02-09 17:40:12 UTC
You should never use those from python, as setting an attribute to the
object has the same purpose. It only allows you to "retrieve" untyped
pointers set by someone else, which often results in a crash.
Comment 1 Steve Frécinaux 2011-02-09 17:40:14 UTC
Created attachment 180495 [details] [review]
Do not bind gobject_get_data() and gobject_set_data()

They will basically cause a crash if misused, and you can always use a
python member attribute instead.
Comment 2 Steve Frécinaux 2011-06-09 07:42:35 UTC
Do you guys have any opinion on this change for pygobject 3?
Comment 3 johnp 2011-06-10 16:03:08 UTC
You need to set data when creating your own container but it is a void pointer so the python pointer gets set instead of the wrapped C pointer.  I agree it is useless in that case.
Comment 4 Martin Pitt 2012-04-04 12:19:48 UTC
This makes sense to me, much better to use Python attributes. Now, right after a stable release, is a good time to push changes like these.

I updated your patch to apply to current master, and pushed. Thanks!
Comment 5 Johan (not receiving bugmail) Dahlin 2012-05-07 20:37:38 UTC
While I agree that using attributes is almost always a better idea than set/get_data there should at least be an opportunity for end users to migrate their apis first, with warnings. 

The implementation could perhaps be simplified to do a simple 

def set_data(self, key, value):
  self._pygobject_data[key] = value.

def get_data(self, key):
  return self._pygobject_data.get(key)

Could even be done in python, as the metaclass is pure-python code.

I'm reopening this.
Comment 6 Tomeu Vizoso 2012-05-08 09:28:34 UTC
(In reply to comment #5)
> 
> Could even be done in python, as the metaclass is pure-python code.

That's a great idea, specially if we raise a DeprecationWarning.
Comment 7 Johan (not receiving bugmail) Dahlin 2012-05-09 15:34:11 UTC
Or an even more evil variant;

    set_data = lambda *args : setattr(*args)
    get_data = lambda *args : getattr(*args)
Comment 8 Martin Pitt 2012-05-14 16:48:22 UTC
Created attachment 214011 [details] [review]
(broken) attempt to add them back in the metaclass

Johan, can you please give me a hint what you mean with "do this in the metaclass"? I assumed you meant something like the attached patch attempt, but that doesn't work.
Comment 9 Johan (not receiving bugmail) Dahlin 2012-05-14 22:50:32 UTC
I thought impl, it in the metaclass itself would work?
Comment 10 Martin Pitt 2012-05-15 04:18:30 UTC
(In reply to comment #9)
> I thought impl, it in the metaclass itself would work?

No, it seems GObjectMeta is not being called for GObject.GObject. Adding a print() to its constructor shows:

('GObjectMeta init', <class 'gi.repository.GObject.InitiallyUnowned'>, 'InitiallyUnowned')
('GObjectMeta init', <class 'test_gobject.A'>, 'A')
('GObjectMeta init', <class 'test_gobject.ContextTestObject'>, 'ContextTestObject')
('GObjectMeta init', <class 'test_gobject.TestObject'>, 'TestObject')
testGObjectModule (test_gobject.TestGObjectAPI) ... ok
testGetSetData (test_gobject.TestGObjectAPI) ... ERROR

======================================================================
ERROR: testGetSetData (test_gobject.TestGObjectAPI)
----------------------------------------------------------------------
Traceback (most recent call last):
  • File "/home/martin/upstream/pygobject/tests/test_gobject.py", line 23 in testGetSetData
    obj.set_data('int', 1)
AttributeError: 'gi._gobject.GObject' object has no attribute 'set_data'

----------------------------------------------------------------------

I don't yet know how the metaclass works, doing some RTFS now..
Comment 11 Johan (not receiving bugmail) Dahlin 2012-05-15 17:48:06 UTC
Okay, GObject.Object it not using that metaclass, but gobject.GObject is, go figure. Perhaps we need an override here.
Comment 12 Colin Watson 2012-06-11 15:49:50 UTC
This broke Ubuntu's update-manager application, which was using get_data/set_data for bits and pieces of internal communication.  Nothing very important, and easy to fix, but some kind of deprecation cycle would have been nice.
Comment 13 Martin Pitt 2012-06-20 09:22:44 UTC
As it's inordinately complicated to provide a python backwards compat shim, I reverted the original patch and added a deprecation warning for now:

$ jhbuild run python3 -c 'from gi.repository import GObject; o = GObject.Object(); o.set_data("foo", 1); print(o.get_data("foo"))'

** (process:28774): WARNING **: GObject.get_data() and set_data() are deprecated. Use normal Python attributes instead

** (process:28774): WARNING **: GObject.get_data() and set_data() are deprecated. Use normal Python attributes instead

http://git.gnome.org/browse/pygobject/commit/?id=73531fd7820bd1922347bd856298d68205a27877

We should reapply this in GNOME 3.8 then, when application authors have ported their stuff.
Comment 14 André Klapper 2012-06-26 12:17:22 UTC
Patch status has been "accepted-commit_after_freeze" for 18 months now.
Which freeze does this exactly refer to? Any patch status update to set?
Comment 15 Martin Pitt 2012-06-26 12:30:37 UTC
Andre, actually I only flipped it back to "accepted-commit-after-freeze" two days ago. This patch is targetted at GNOME 3.8, but that milestone does not exist in bugzilla yet. This was the next best thing as a "patch for next cycle" queue. But if it's confusing for the release team, I'll flip it back to "reviewed".
Comment 16 André Klapper 2012-06-26 12:48:18 UTC
Comment on attachment 180495 [details] [review]
Do not bind gobject_get_data() and gobject_set_data()

(In reply to comment #15)
> Andre, actually I only flipped it back to "accepted-commit-after-freeze" two
> days ago. This patch is targetted at GNOME 3.8, but that milestone does not
> exist in bugzilla yet.

Well, there are no Milestones *at all* for pygobject it seems. :P

I see. I think it's quite appropriate then. :)
Comment 17 Martin Pitt 2012-06-26 12:56:54 UTC
Ah, indeed. I added a "GNOME 3.8" milestone now, and target this bug to it.
Comment 18 Martin Pitt 2012-10-23 07:18:06 UTC
Comment on attachment 180495 [details] [review]
Do not bind gobject_get_data() and gobject_set_data()

Now that we opened the 3.7.x cycle, I committed this, together with dropping the corresponding documentation.

Thanks!