[sqlalchemy] Flushed PickleType data disappearing

2015-02-26 Thread SQLRook
I'm having an issue where a list of user-defined objects is disappearing as 
a function goes out of scope.  The list is stored in a PickleType column, 
and as that type does not track changes in the objects of the list, I am 
(knowingly, inefficiently) forcing the column to become dirty by setting 
the corresponding Python object to an empty list, and then to the new list 
value.  This is Python 2.7.3 with SQLAlchemy 0.9.8.  The session I'm using 
in the following code is created from a sessionmaker with default values 
aside form *expire_on_commit*, which is False.

The declaration of the class containing the list is simplified to the 
following:

class Target:
__tablename__ = 'targets'
id = Column(Integer, primary_key=True)
name = Column(Unicode)
targetList = Column(PickleType, default=[])


def run(dbSession):
targetInstance = makeTI(dbSession)#adds instance to session, flushes
modifyList(targetInstance, dbSession, data)#blinks list values, dirties 
object in session.  Flushes changes, and all list contents are still 
subsequently present
assert not any(dbSession.dirty)#assert passes
assert not dbSession.is_modified(targetInstance)#assert passes
print 'targetInstance list contents after init: ' + 
str(targetInstance.targetList)#prints list contents as expected
#last place list contents are present. Upon return of run(), list will 
be empty again
return

After flow of control returns to the caller of run(), a commit is done, 
then targetInstance is queried from the session, and the list is empty.  
Even if the list is accessed, or explicitly refreshed from the session, the 
list is empty.  How is that possible if the once-dirty session was flushed?

I know that there is optional in-place mutation tracking, but that's not 
being used here.
The relevant links are the official 
 mutable 
docs, an extended conversation 

 
with Mike on BitBucket.

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] idle in transaction using ZopeTransactionExtension with postgres

2015-02-26 Thread Wichert Akkerman

> On 26 Feb 2015, at 17:02, Robert Daniels  wrote:
> 
> 
> I'm using ZopeTransactionExtension (postgresql) as:
> 
> DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
> Base = declarative_base()
> 
> 
> When I invoke 
> 
> result = DBSession.execute("some sql query")
> 
> The result comes back fine, however I notice when I review the server status 
> I see 'idle in transaction' state.
> If I execute DBSession.execute("commit") following the query execution, it 
> returns to 'idle'.
> 
> I would have thought that DBSession would do this for me….

It doesn’t: you are still responsible for managing transactions. The 
zope.sqlalchemy has documentation with examples you can read at 
https://pypi.python.org/pypi/zope.sqlalchemy 


Regards,
Wichert.

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] idle in transaction using ZopeTransactionExtension with postgres

2015-02-26 Thread Robert Daniels

I'm using ZopeTransactionExtension (postgresql) as:

DBSession = 
scoped_session(sessionmaker(extension=ZopeTransactionExtension()))Base = 
declarative_base()


When I invoke 

result = DBSession.execute("some sql query")

The result comes back fine, however I notice when I review the server status I 
see 'idle in transaction' state.
If I execute DBSession.execute("commit") following the query execution, it 
returns to 'idle'.

I would have thought that DBSession would do this for me


-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] relationship problem

2015-02-26 Thread Julien Cigar
On Wed, Feb 25, 2015 at 06:10:55PM -0500, Michael Bayer wrote:
> 
> 
> Julien Cigar  wrote:
> 
> > On Thu, Feb 19, 2015 at 11:31:10AM -0500, Michael Bayer wrote:
> >> Julien Cigar  wrote:
> >> 
> >>> On Thu, Feb 19, 2015 at 02:45:43PM +0100, Julien Cigar wrote:
>  Hello,
>  
>  I'm using SQLAlchemy 0.9.8 with PostgreSQL and the reflection feature of
>  SQLAlchemy.
>  
>  I have the following tables (only relevant parts are show):
>  https://gist.github.com/silenius/390bb9937490730741f2
>  
>  and the "problematic" mapper is the one of my association object:
>  https://gist.github.com/silenius/1559a7db65ed30a1b079
>  
>  SQLAlchemy complains with the following error:
>  "sqlalchemy.exc.InvalidRequestError: One or more mappers failed to
>  initialize - can't proceed with initialization of other mappers.
>  Original exception was: Could not locate any simple equality expressions
>  involving locally mapped foreign key columns for primary join condition
>  'pool_invite_result.pool_invite_pool_id = pool_invite.pool_id AND
>  pool_invite.pool_id = pool.id' on relationship PoolAccountResult.pool.
>  Ensure that referencing columns are associated with a ForeignKey or
>  ForeignKeyConstraint, or are annotated in the join condition with the
>  foreign() annotation. To allow comparison operators other than '==', the
>  relationship can be marked as viewonly=True."
>  
>  The problem is that in the PoolAccountResult mapper I want a
>  relationship to the Pool but the link is made through an intermediate
>  table (pool_invite) ..
>  
>  Any idea how to handle this with SQLAlchemy ?
>  
>  Thanks :)
>  
>  Julien
> >>> 
> >>> ... and I'm answering to myself: it seems to work with
> >>> https://gist.github.com/silenius/e7e59c96a7277fb5879f 
> >>> 
> >>> does it sound right ?
> >> 
> >> Sure.  Also, you could use automap which does figure these out in simple 
> >> cases: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/automap.html
> > 
> > always with this, any idea why SQLAlchemy inserts NULL and
> > NULL for my two relationship (line 51-79) instead of the pool_obj and
> > dup.owner ids (line 89-90), https://dpaste.de/1Trz ..?
> 
> getting a 404 on that link.

Hi Mike,

Thanks for your help!

I took the time to make a complete test case, available from here
https://gist.github.com/silenius/96d6ed2544d14753853f

I'm using PostgreSQL, and I checked that all constraints are properly
created on server-side but I haven't checked with sqllite:// 

> 
> 
> 
> 
> 
> > 
> > Thanks,
> > Julien
> > 
> > 
>  -- 
>  Julien Cigar
>  Belgian Biodiversity Platform (http://www.biodiversity.be)
>  PGP fingerprint: EEF9 F697 4B68 D275 7B11  6A25 B2BB 3710 A204 23C0
>  No trees were killed in the creation of this message.
>  However, many electrons were terribly inconvenienced.
>  
>  -- 
>  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 http://groups.google.com/group/sqlalchemy.
>  For more options, visit https://groups.google.com/d/optout.
> >>> 
> >>> 
> >>> 
> >>> -- 
> >>> Julien Cigar
> >>> Belgian Biodiversity Platform (http://www.biodiversity.be)
> >>> PGP fingerprint: EEF9 F697 4B68 D275 7B11  6A25 B2BB 3710 A204 23C0
> >>> No trees were killed in the creation of this message.
> >>> However, many electrons were terribly inconvenienced.
> >>> 
> >>> -- 
> >>> 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 http://groups.google.com/group/sqlalchemy.
> >>> For more options, visit https://groups.google.com/d/optout.
> >> 
> >> -- 
> >> 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 http://groups.google.com/group/sqlalchemy.
> >> For more options, visit https://groups.google.com/d/optout.
> > 
> > -- 
> > Julien Cigar
> > Belgian Biodiversity Platform (http://www.biodiversity.be)
> > PGP fingerprint: EEF9 F697 4B68 D275 7B11  6A25 B2BB 3710 A204 23C0
> > No trees were killed in the creation of this message.
> > However, many electrons were terribly inconvenienced.
> > 
> > -- 
> > You received this message because you

[sqlalchemy] Re: calchipan

2015-02-26 Thread info . yazzoom
Hi mdob,

I have the same TypeError, How have you solved it?

Thanks

Op zaterdag 25 oktober 2014 15:48:40 UTC+2 schreef mdob:
>
> Hi, 
> I was trying to use SQLAlchemy with Pandas - CALCHIPAN. 
> Installed sqlalchemy, numpy and pandas from pip, then calchipan from 
> source. 
>
> SQLAlchemy==0.9.8
> argparse==1.2.1
> calchipan==0.1.0dev
> ipython==2.3.0
> numpy==1.9.0
> pandas==0.15.0
> python-dateutil==2.2
> pytz==2014.7
> six==1.8.0
> wsgiref==0.1.2
>
>
> tried the example from https://bitbucket.org/zzzeek/calchipan/
>
> and got  
> TypeError: "value" parameter must be a scalar or dict, but you passed a 
> "list" from pandas
>
>
> full traceback: http://pastie.org/9674778
>
> Am I using wrong versions?
>

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.