Ok we'll have to ensure this doesn't break anything, that line doesn't
seem to be covered in the current unit tests

Roel van Os wrote:
> Hi Michael,
>
> On 12-06-2009 16:22, Michael Bayer wrote:
>> this is likely a bug.  try out the patch below (against the latest 0.5
>> release):
>>
>
> After applying the patch it works perfectly. Thanks a lot!
>
> Regards,
> Roel
>
>> Index: lib/sqlalchemy/orm/state.py
>> ===================================================================
>> --- lib/sqlalchemy/orm/state.py      (revision 6049)
>> +++ lib/sqlalchemy/orm/state.py      (working copy)
>> @@ -111,8 +111,8 @@
>>               return None
>>           elif hasattr(impl, 'get_collection'):
>>               return impl.get_collection(self, dict_, x,
>> passive=passive)
>> -        elif isinstance(x, list):
>> -            return x
>> +#        elif isinstance(x, list):
>> +#            return x
>>           else:
>>               return [x]
>>
>>
>>
>>
>> Roel van Os wrote:
>>
>>> Hi all,
>>>
>>> In my program I'm using PGArray to store a list of strings in the
>>> database (defined as text[] in the schema).
>>>
>>> When I use Session.merge to create a copy of an object in the current
>>> session, the list is converted to a single string (the first from the
>>> list) in the copy. I've placed an example below. dont_load True or
>>> False
>>> doesn't make a difference.
>>>
>>> I've tested with SQLAlchemy 0.5.4 and 0.4.6.
>>>
>>> Any idea what the problem might be and what I can do about it?
>>>
>>> Thanks,
>>> Roel van Os
>>>
>>> Example code:
>>>
>>> #!/usr/bin/env python
>>> from sqlalchemy import *
>>> from sqlalchemy.sql import *
>>> from sqlalchemy.orm import *
>>> from sqlalchemy.ext.declarative import declarative_base
>>> from sqlalchemy.databases.postgres import PGArray
>>>
>>> Base = declarative_base()
>>>
>>> class TestClass(Base):
>>>       __tablename__ = 'testclass'
>>>
>>>       id              = Column(Integer, primary_key=True)
>>>       test_array      = Column(PGArray(Text))
>>>
>>> dburl = 'postgres://xxxx:x...@xxxx/xxxx'
>>> engine = create_engine(dburl, convert_unicode=True, echo=False,
>>> pool_recycle=60)
>>> Session = sessionmaker(bind=engine)
>>> Base.metadata.create_all(engine)
>>>
>>> # Create a test object
>>> s1 = Session()
>>> o1 = TestClass(test_array=['1', '2', '3'])
>>> s1.save(o1)
>>> s1.commit()
>>> o1_id = o1.id
>>> s1.close()
>>>
>>> # Load the test object
>>> s2 = Session()
>>> o2 = s2.query(TestClass).get(o1_id)
>>> print o2.test_array
>>> assert len(o2.test_array) == 3
>>>
>>> # Merge the object into another session
>>> s3 = Session()
>>> o3 = s3.merge(o2, dont_load=True)
>>>
>>> # Should print the same as above, but prints "1"
>>> print o3.test_array
>>> assert len(o3.test_array) == 3
>>>
>>>
>>>
>>
>>
>> >
>>
>
>
> >
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to