Giter VIP home page Giter VIP logo

Comments (4)

jamadden avatar jamadden commented on June 18, 2024

It's not just BTrees, it's any reference to the object. References to persisted objects all include the type so that they can be unghosted:

>>> from ZODB import DB, MappingStorage
>>> from persistent import Persistent
>>> import transaction
>>> db = DB(MappingStorage.MappingStorage())
>>> class X(Persistent): pass
>>> class Y(Persistent): pass
>>> x = X()
>>> conn = db.open()
>>> conn.root()['x'] = x
>>> transaction.commit()
>>> x.__class__ = Y
>>> type(x)
 __main__.Y
>>> x._p_changed = True
>>> transaction.commit()
>>> conn.root()['x']
<__main__.Y at 0x10d3c18c0>
>>> new_conn = db.open()
>>> new_conn.root()['x']
<__main__.X at 0x10d3c9f50>

In general you can't change the __class__ of a persistent object and expect it to be consistently unghosted as the new class unless you can update all the references to it.

This is documented here:

Because the persistent object reference forms include class
information, it is not possible to change the class of a persistent
object for which this form is used. If a transaction changed the
class of an object, a new record with new class metadata would be
written but all the old references would still use the old class.

from btrees.

malthe avatar malthe commented on June 18, 2024

I have tried to devise a "fix" here:

https://github.com/zopefoundation/ZODB/compare/ensure-correct-class-on-ghost-set-state?expand=1

Not sure if it's a good thing.

from btrees.

davisagli avatar davisagli commented on June 18, 2024

https://pypi.python.org/pypi/collective.diversion or https://pypi.python.org/pypi/zodbupdate may be useful

from btrees.

icemac avatar icemac commented on June 18, 2024

We successfully used an approach described in the fourdigits blog.

from btrees.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.