Re: [ZODB-Dev] TypeError: ('object.__new__(SyncedLanguages) is not safe, use Persistence.Persistent.__new__()', ...

2010-12-31 Thread Marius Gedminas
On Fri, Dec 31, 2010 at 08:39:22AM +0100, Godefroid Chapelle wrote:
 Le 31/12/10 04:08, Marius Gedminas a écrit :
  On Fri, Dec 31, 2010 at 02:02:36AM +0100, Godefroid Chapelle wrote:
  I have been fighting all day to understand a bug with the unregistration
  of a utility from a local site.
 
  After unregistration, some instance is left in the _subscribers list of
  the utilities AdapterRegistry in my local site.
 
  Sounds like https://bugs.launchpad.net/zope.component/+bug/551049
...
  Actually, half of it is based on identity, and half on equality; when
  these disagree, you end up with inconsistent state.
 
 Yup
 
  Your example is a good argument for making both halves use equality
  rather than identity.
...
  I think a more fruitful approach would be to fix the zope.component bug
  and then unregister the utility in the normal way.
 
 Marius, did you already try to fix zope.component ?

No.  I didn't have an opinion how to fix it (make both pieces of code
use identity or equality), and I was a bit afraid to touch the internals
in case I broke something.  And it was easy to work around in my code,
so I just chickened out :(

 Is it because it is 
 hard that you accepted the Won't fix ? Or because of lack of time ?

The wontfix is for the obsolete monolithic zope3 package.  The bug is
still open against zope.component.

Although it may need to be fixed in the internals of the adapter
registry which lives, I think, in zope.interface?  I forgot most of the
details :(

  Alternatively, you could hack up a __new__ method to always return the
  same instance, so you can unregister it cleanly before removing the
  code.  This will not work if you have more than one instance in the DB.
 
 Could that __new__ method insert Persistent as a base class if not present ?

No.  In order to change from non-persistent to persistent, you need to
activate and dirty all objects that have references to your
nonpersistent object; it's not enough to change just the object itself.

Marius Gedminas
-- 
The death rate on Earth is:  (computing)  One per person.


signature.asc
Description: Digital signature
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] TypeError: ('object.__new__(SyncedLanguages) is not safe, use Persistence.Persistent.__new__()', ...

2010-12-30 Thread Godefroid Chapelle
Le 31/12/10 02:02, Godefroid Chapelle a écrit :
 Hi,

 I have been fighting all day to understand a bug with the unregistration
 of a utility from a local site.

 After unregistration, some instance is left in the _subscribers list of
 the utilities AdapterRegistry in my local site.

 This avoids me to remove the code as it does leave a broken object.

 I have come to the conclusion that the code that first registered the
 utility is the culprit : the utility itself is not persistent.

 It seems that the utility instance is unserialized at least two times
 during unregistration, which leads (if I understand well) to two
 different objects in memory.

 This breaks the unsubscription algorithm that is based on object identity.

 I naively tried to introduce the Persistent base class into the utility
 calss. When I try to access the utility instance again, I get the error
 mentioned in the subject of this mail :

 TypeError: ('object.__new__(SyncedLanguages) is not safe, use
 Persistence.Persistent.__new__()',function _reconstructor at
 0x1004297d0, (class
 'Products.LinguaPlone.vocabulary.SyncedLanguages',type 'object', None))

 If I understand well, the a posteriori introduction of Persistent cannot
 happen alone.

 Can anyone tell me what I should do add to the class I try to make it
 actually persistent ?

Let's try to make an understandable question :

Can anyone tell me what I should add to the class to make it actually 
persistent, while making the old instances unserializable ?


 PS: It is late here, I hope I have not told too many silly things


-- 
Godefroid Chapelle (aka __gotcha) http://bubblenet.be

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] TypeError: ('object.__new__(SyncedLanguages) is not safe, use Persistence.Persistent.__new__()', ...

2010-12-30 Thread Marius Gedminas
On Fri, Dec 31, 2010 at 02:02:36AM +0100, Godefroid Chapelle wrote:
 I have been fighting all day to understand a bug with the unregistration 
 of a utility from a local site.
 
 After unregistration, some instance is left in the _subscribers list of 
 the utilities AdapterRegistry in my local site.

Sounds like https://bugs.launchpad.net/zope.component/+bug/551049

 This avoids me to remove the code as it does leave a broken object.
 
 I have come to the conclusion that the code that first registered the 
 utility is the culprit : the utility itself is not persistent.
 
 It seems that the utility instance is unserialized at least two times 
 during unregistration, which leads (if I understand well) to two 
 different objects in memory.
 
 This breaks the unsubscription algorithm that is based on object identity.

Actually, half of it is based on identity, and half on equality; when
these disagree, you end up with inconsistent state.

Your example is a good argument for making both halves use equality
rather than identity.

 I naively tried to introduce the Persistent base class into the utility 
 calss. When I try to access the utility instance again, I get the error 
 mentioned in the subject of this mail :
 
 TypeError: ('object.__new__(SyncedLanguages) is not safe, use 
 Persistence.Persistent.__new__()', function _reconstructor at 
 0x1004297d0, (class 
 'Products.LinguaPlone.vocabulary.SyncedLanguages', type 'object', None))
 
 If I understand well, the a posteriori introduction of Persistent cannot 
 happen alone.
 
 Can anyone tell me what I should do add to the class I try to make it 
 actually persistent ?

I think a more fruitful approach would be to fix the zope.component bug
and then unregister the utility in the normal way.

Alternatively, you could hack up a __new__ method to always return the
same instance, so you can unregister it cleanly before removing the
code.  This will not work if you have more than one instance in the DB.

Fixing up _subscribers directly is also a possible workaround, if you're
feeling brave.

Marius Gedminas
-- 
/* Intel provided a special instruction to clear the TS bit for people too cool
 * to use write_cr0() to do it.  This clts instruction is faster, because all
 * the vowels have been optimized out. */
-- lguest source code


signature.asc
Description: Digital signature
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] TypeError: ('object.__new__(SyncedLanguages) is not safe, use Persistence.Persistent.__new__()', ...

2010-12-30 Thread Godefroid Chapelle
Le 31/12/10 04:08, Marius Gedminas a écrit :
 On Fri, Dec 31, 2010 at 02:02:36AM +0100, Godefroid Chapelle wrote:
 I have been fighting all day to understand a bug with the unregistration
 of a utility from a local site.

 After unregistration, some instance is left in the _subscribers list of
 the utilities AdapterRegistry in my local site.

 Sounds like https://bugs.launchpad.net/zope.component/+bug/551049

 This avoids me to remove the code as it does leave a broken object.

 I have come to the conclusion that the code that first registered the
 utility is the culprit : the utility itself is not persistent.

 It seems that the utility instance is unserialized at least two times
 during unregistration, which leads (if I understand well) to two
 different objects in memory.

 This breaks the unsubscription algorithm that is based on object identity.

 Actually, half of it is based on identity, and half on equality; when
 these disagree, you end up with inconsistent state.

Yup

 Your example is a good argument for making both halves use equality
 rather than identity.

 I naively tried to introduce the Persistent base class into the utility
 calss. When I try to access the utility instance again, I get the error
 mentioned in the subject of this mail :

 TypeError: ('object.__new__(SyncedLanguages) is not safe, use
 Persistence.Persistent.__new__()',function _reconstructor at
 0x1004297d0, (class
 'Products.LinguaPlone.vocabulary.SyncedLanguages',type 'object', None))

 If I understand well, the a posteriori introduction of Persistent cannot
 happen alone.

 Can anyone tell me what I should do add to the class I try to make it
 actually persistent ?

 I think a more fruitful approach would be to fix the zope.component bug
 and then unregister the utility in the normal way.

Marius, did you already try to fix zope.component ? Is it because it is 
hard that you accepted the Won't fix ? Or because of lack of time ?

 Alternatively, you could hack up a __new__ method to always return the
 same instance, so you can unregister it cleanly before removing the
 code.  This will not work if you have more than one instance in the DB.

Could that __new__ method insert Persistent as a base class if not present ?

 Fixing up _subscribers directly is also a possible workaround, if you're
 feeling brave.

 Marius Gedminas

Thanks for your help.

-- 
Godefroid Chapelle (aka __gotcha) http://bubblenet.be
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev