On Tue, Aug 7, 2018 at 2:44 AM, wei zhang <[email protected]> wrote:
>
> I am sorry I did not make it clear.  I am trying to develop new application,
> which requires modern sqlalchemy. New application shares user data with old
> application, so both applications must use same datatype declaration.  As
> old application had used mutable PickleType, So I think I can only use
> PickleType, not MutableList or MutableDict in new application. Is there
> simple ways to  make PickleType mutable in modern sqlalchemy?

it depends on what you are pickling.     The object that's being
pickled, as things change on it, needs to send events.
http://docs.sqlalchemy.org/en/latest/orm/extensions/mutable.html#establishing-mutability-on-scalar-column-values
shows the basic idea.

Another way might be to scan for it in the before_flush() event:
http://docs.sqlalchemy.org/en/latest/orm/events.html?highlight=before_flush#sqlalchemy.orm.events.SessionEvents.before_flush

and then use flag_modified:
http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.attributes.flag_modified
 if you detect a change.

However you still need to be able to detect that the to-be-pickled
object has changed in some way since it was loaded.


Often with pickled things, you don't actually need the "mutable"
aspect, it depends on what you are doing.   if you just re-assign the
mapped attribute to itself, it will get picked up.   You might want to
consider if "mutable=True" is actually needed or if you can rework
those parts that do need it.





>
> On Monday, August 6, 2018 at 10:23:36 PM UTC+8, Mike Bayer wrote:
>>
>> On Mon, Aug 6, 2018 at 3:09 AM, wei zhang <[email protected]> wrote:
>> > Hi. I have an old application using version 0.7.8,  which  has
>> > 'mutable=True'  in PickleType to make PickleType mutable. I want new
>> > application, which uses new version of sqlalchemy to access the same
>> > database, to be compatible with old application. I can't use MutableList
>> > or
>> > MutableSet  in new application because old application doesn't
>> > understand
>> > them.
>> > I think the best way is putting back 'mutable=True' to PickleType? Is
>> > there
>> > simple ways to do this?
>>
>>
>> I'm assuming "old application doesnt understand them" means it is
>> still using 0.7.8, and you want that same code to also work with
>> modern SQLAlchemy.     Your "new" application wants to use "import" to
>> use the same code from the "old" application, I assume.
>>
>> In the "old" application use version detection:
>>
>>
>> from sqlalchemy import __version__
>>
>> sqlalchemy_version = tuple([int(x) for x in re.findall(r'(\d+)',
>> __version__)])
>>
>> if sqlalchemy_version < (0, 9):
>>     pickle_type = PickleType(mutable=True)
>> else:
>>    from sqlalchemy.ext.mutable import MutableDict
>>    pickle_type = MutableDict.as_mutable(PickleType())
>>
>> then you just use pickle_type.
>>
>>
>>
>>
>>
>>
>>
>>
>> >
>> > --
>> > SQLAlchemy -
>> > The Python SQL Toolkit and Object Relational Mapper
>> >
>> > http://www.sqlalchemy.org/
>> >
>> > To post example code, please provide an MCVE: Minimal, Complete, and
>> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> > description.
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "sqlalchemy" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [email protected].
>> > To post to this group, send email to [email protected].
>> > Visit this group at https://groups.google.com/group/sqlalchemy.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to