issue is local to 1.2 so isn't present in production systems

On Mon, Dec 4, 2017 at 4:26 PM, Mike Bayer <mike...@zzzcomputing.com> wrote:
> On Mon, Dec 4, 2017 at 2:18 PM, Olaf <bastien...@gmail.com> wrote:
>> Hello,
>>
>>
>>
>> This mail is the continuation of this question:
>> https://groups.google.com/forum/#!topic/sqlalchemy/Ba7urbeZBqQ
>>
>>
>>
>> The problem being different, I prefer to open a new topic.
>>
>>
>>
>> I am currently meeting a problem regarding generic associations and the use
>> of MutableList associated to the array type of postgres.
>>
>>
>>
>> I coded two versions of the same case:
>>
>> - the first one uses a generic association. The attribute "text" should be a
>> MutableList but suddenly becomes a "List" during the first commit. The next
>> changes are therefore not longer detected and the data are not actualized in
>> the database
>>
>> - the second example is a classical relationship. In this case, the
>> attribute "text" is a MutableList and don't changes during the commits.
>> Everything works as it should and the data are actualized in the database
>
> this is 
> https://bitbucket.org/zzzeek/sqlalchemy/issues/4141/array-does-not-fire-attachment-events.
>   Please use @declared_attr for now.
>
> class Mixin(object):
>     @declared_attr
>     def data(cls):
>         return Column(MutableList.as_mutable(postgresql.ARRAY(String)))
>
>
>
>
>>
>>
>>
>> It will be easier to see the problem with the two examples and their output.
>>
>>
>> The examples are attached.
>>
>>
>>
>> Example 1 - Generic Association Code (don't works as it should):
>>
>>
>>
>> Output:
>>
>>
>>
>>>>>
>> Text before commit 1:  ['Rex is a', 'good dog...']
>> Type before commit 1:  <class 'sqlalchemy.ext.mutable.MutableList'>
>> Commit 1
>> Type after commit 1:  <class 'list'>
>> We append duck sentence :  ['Rex is a', 'good dog...', 'but I prefer
>> ducks.']
>> Commit 2
>> Text after commit 2 :  ['Rex is a', 'good dog...']
>>>>>
>>
>>
>>
>>
>> Example 2 - Classical relationship (works fine):
>>
>>
>>
>> Output:
>>
>>
>>
>>>>>
>> Text before commit 1:  ['Rex is a', 'good dog...']
>> Type before commit 1:  <class 'sqlalchemy.ext.mutable.MutableList'>
>> Commit 1
>> Type after commit 1:  <class 'sqlalchemy.ext.mutable.MutableList'>
>> We append duck sentence :  ['Rex is a', 'good dog...', 'but I prefer
>> ducks.']
>> Commit 2
>> Text after commit 2 :  ['Rex is a', 'good dog...', 'but I prefer ducks.']
>>>>>
>>
>>
>>
>>
>> I don't know if it helps but I noticed that the __init__ method of the class
>> Description doesn't have exactly the same behavior in the two examples:
>>
>>
>>
>> - in the Generic Association Code example, the "self.text = MutableList()"
>> in the __init__ method of the class Description is not really important. It
>> could also be "self.text = []" instead. In all cases, text is a MutableList.
>>
>> - in the Classical relationship example, if the __init__ method of the class
>> Description contains "self.text = MutableList()", the attribute text will be
>> a MutableList and if the __init__ method contains "self.text = []", it will
>> be a List.
>>
>>
>>
>> Does someone have an explanation ?
>>
>>
>>
>> Thank you !
>>
>> --
>> 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 sqlalchemy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sqlalchemy@googlegroups.com.
>> 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to