Re: [sqlalchemy] interaction between lazy=noload and contains_eager()

2013-01-30 Thread Pau Tallada
Oh, sorry, i supposed thaty contains_eager only worked for relationships,
and not for other kind of attributes :D

That's great!

Thanks!

2013/1/28 Michael Bayer mike...@zzzcomputing.com

 what additional behaviors are you looking for that the @property approach
 isn't giving you ? Options include turning it into a synonym() which
 would allow it to be a little bit more transparent.





 On Jan 28, 2013, at 4:55 AM, Pau Tallada wrote:

 Hi,

 Sorry to insist on this :P
 But there is any way to get this kind of behaviour, the virtual
 column/relationship?

 Thanks!

 Pau.

 2013/1/24 Pau Tallada tall...@pic.es

 Hi Michael,

 As always, thank you very much for your dedication :)
 I recognize that I am always trying to reach the edges of your wonderful
 library.

 That example is just a sample of what I am trying to accomplish:
 Some sort of virtual column/relationship, that it is not mapped to any
 column, but it can be batch-loaded in a set of instances using a
 carefully-crafted contains_eager.
 That way, using a descriptor, if the attribute is not in __dict__ (as you
 just pointed), i can craft a CTE to fetch the attribute.
 Or, if the user knows better, will use a with_transformation on top of
 his query to fetch the attribute for all the queried instances.

 Thank you again!


 2013/1/23 Michael Bayer mike...@zzzcomputing.com


 On Jan 23, 2013, at 4:28 PM, Pau Tallada wrote:

 Hi,

 I have prepared a sample of code to ilustrate this behaviour :)

 Summarizing:

 session.expunge_all()
 n2 =
 session.query(Node).filter_by(name='n2').options(joinedload('ancestors')).one()
 print n2.ancestors


 AND:

 session.expunge_all()
 n2 = session.query(Node).filter_by(name='n2').one()
 n2 =
 session.query(Node).filter_by(name='n2').options(joinedload('ancestors')).one()
 print n2.ancestors


 do NOT produce the same result when the collection is lazy='noload'.

 In the latter, the collection is empty, even after we fetch its contents
 with a joinedload.


 Ah well without actually running it, I can say that the joinedload for
 the second case won't have an effect like that, since n2.ancestors is
 already loaded, as the effect of noload is to populate the attribute
 with an empty collection (or None for a scalar).   noload is not very
 widely used and was sort of an added-in strategy from very early versions.

 What it appears like you're looking for on anscestors is just the
 default lazy loader.  Above, when you load n2 without any options,
 n2.anscestors will not be present in n2.__dict__ at all, and that's what
 unloaded means.   Hitting it again with the joinedload() should populate
 the collection.

 But there's not really a built in system of, don't load this mapped
 attribute, but also don't load anything when touched.   So if you stuck
 with noload, you'd have to call expire() on ancestors first in order to
 get a subsequent loader to populate it.

 I guess if I really wanted an attribute like this, I'd need to wrap it
 under a @property:

 @property
 def ancestors(self):
 if _ancestors in self.__dict__:
 return self._anscestors
else:
 return None

 if I think of a better way I'll let you know.







 2013/1/23 Pau Tallada tall...@pic.es

 Ok, thank you very much :D

 I'll keep poking, and i'll try to provide a sample code :P


 2013/1/23 Michael Bayer mike...@zzzcomputing.com


 On Jan 23, 2013, at 6:49 AM, Pau Tallada wrote:

 
  One final comment. With the contains_eager query, the instances that
 are part of the collection are retrieved from the database but not stored
 on the identity_map. Is that also the expected behaviour, isn't it?

 I need to read your whole email more closely but on this point, that's
 not true at all.  Every object that the Session loads from the database
 goes directly to the identity map.The identity map is weak 
 referencing,
 so if no other references remain to a particular object, it will disappear
 from the identity map also, but that implies that object is not accessible
 anywhere else either.

 Since it seems like you've been poking around, you might want to
 continue poking around some more given that information until I have time
 to look at the rest of your email.


 --
 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.




 --
 --
 Pau Tallada Crespí
 Dep. d'Astrofísica i Cosmologia
 Port d'Informació Científica (PIC)
 Tel: +34 93 586 8233
 --




 --
 --
 Pau Tallada Crespí
 Dep. d'Astrofísica i Cosmologia
 Port d'Informació Científica (PIC)
 Tel: +34 93 586 8233
 --


 --
 You received this message because you are 

[sqlalchemy] Mandatory fields in tables referencing each other

2013-01-30 Thread Matteo
Hello everybody,

I'm currently using PostgreSQL 8.4.9 and SQLAlchemy 0.7.9, and there's an 
issue I just can't seem to solve.
There are 2 tables, User and People. The idea behind this is to have User's 
people_id column point to that user's personal data, and People's 
user_id point to the user who created that person. Neither field can be 
NULL. This creates an obvious circular dependency when inserting the very 
first user and its personal data, hence the use of post_update and use_alter
.
Each schema is in a separate file, so they can't import each other. These 
are their structures:

class User(DeclarativeBase):
__tablename__ = 'user'
id = Column(Integer,autoincrement=True,primary_key=True)
people_id = Column(Integer, ForeignKey('people.id', use_alter=True, 
name='alter_people_id'), nullable=False, unique=True)
logname = Column(Unicode(200), unique=True)
password = Column(Unicode(128))

people = relation(People, primaryjoin = People.id == people_id, 
post_update=True)



class People(DeclarativeBase):
__tablename__ = people
id = Column(Integer, autoincrement=True, primary_key=True)
name = Column(Unicode(128))
[...]
user_id = Column(Integer, ForeignKey('user.id', use_alter=True, 
name='alter_user_id'), nullable=False)

Here's what I'm trying to do:

user = User()
user.logname = 'sysadmin'
user.password = 'blah'
user.id = 1
user.people_id = 1
session.add(user)

ppl = People()
ppl.name = 'sysadmin'
ppl.id = 1
ppl.user_id = 1
session.add(ppl)

session.flush()
transaction.commit()

This raises an IntegrityError (insert or update on table user violates 
foreign key constraint alter_people_id). I tried using 
session.add_all([usr,ppl]) instead of session.add, switching the order in 
which data is added to the current session, giving the use_alter attirbute 
to only one of the tables, and the best I can get is a different 
IntegrityError (this time on the other table, violating the other 
constraint).

Thanks in advance to whoever can help 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] Session identity map and PyPy

2013-01-30 Thread George Sakkis
Hello,

I am in the process of migrating to PyPy and have a handful of unit test 
failing due to the different garbage collector and SQLAlchemy's usage of 
weak references in the Session identity map. Most failures are probably 
safe to ignore and all of them are fixed after manually calling 
gc.collect() somewhere in the test. 

One specific failure though looks more worrying: a Session.rollback() call 
in the test's tearDown() method raises InvalidRequestError: Can't attach 
instance `X`; another instance with key (class `X`, (8L, 1L)) is already 
present in this session. Before digging deeper, any idea on why it is 
triggered here and not in any other test? Is there another/better way to 
prevent it other than calling gc.collect() before Session.rollback() (and 
perhaps other Session operations)? 

More generally, are there any other known issues and caveats of running 
SQLAlchemy on PyPY? 

Thanks for any tip,

George

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Problems with retroactive changes to Query objects

2013-01-30 Thread Hans Meine
Hi Michael!

Am Dienstag, 29. Januar 2013, 12:23:01 schrieb Michael Bayer:
 … it's usually going to complicate
 things if you mix implicit and explicit joins together.   The issue should
 be solved if you create a clean string of joins:
 
 s.query(results1.id, results2.id).select_from(results1).join(results2,
 results1.foo=results2.bar).join(...).join(...)

Thank you for the quick and helpful answer and the hint to select_from(); you 
are right that this solves my main problem (it does suffer from the same bad 
performance, but that's most likely a problem with my ERM).

 that way when you add another join to OutputParameterValue the query will
 not have any confusion in how to string this additional JOIN.

I am still not sure if this confusion isn't a bug or weakness in SA that 
should be either fixed or handled with a more explicit error message.

E.g. the join() could raise an error instead of silently throwing the first 
part of the FROM clause away.  (OTOH, I don't see why the latter has to happen 
in the first place.)

Thanks again, and have a nice day,
  Hans

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Michael Bayer
the PDFS have generated very poorly for quite some time and readthedocs 
environment is not able to adapt to the many warnings it generates for 
SQLAlchemy's documentation.   I've was n the Sphinx list a few years ago at 
this point asking for solutions regarding some of these warnings and was not 
able to get help on them - some of the constructs that Sphinx allows (and which 
we really need, namely code examples underneath a :param:) aren't compatible 
with their LaTeX model.I don't have the resources personally to keep 
banging my head against the immensely antiquated LaTeX tools, not to mention 
readthedocs not getting around to fixing things either, so I've taken the PDF 
links off the site.


   

On Jan 30, 2013, at 2:50 AM, Vraj Mohan wrote:

 Hi,
 
 I noticed that documents in PDF for 0.8 and development are not being 
 generated in readthedocs.org.
 
 I tried to build these myself with a development snapshot and had the same 
 failures.
 
 I then noticed that if a pickled environment was already created, the PDF 
 would be generated fine. In other words, make pickle, make html, etc 
 would create a pickled environment which would then cause make latexpdf to 
 succeed.
 
 I am not an expert on Sphinx - I thought this would be useful information for 
 someone more knowledgeable than me.
 
 --Vraj Mohan
 
 -- 
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Problems with retroactive changes to Query objects

2013-01-30 Thread Michael Bayer

On Jan 30, 2013, at 8:47 AM, Hans Meine wrote:

 
 I am still not sure if this confusion isn't a bug or weakness in SA that 
 should be either fixed or handled with a more explicit error message.

the usage pattern as is will likely never be feasible;  SELECT * FROM A, B 
JOIN C on onclause, and then to say JOIN A to D onto that implies the 
statement would then be SELECT * FROM A JOIN D  onclause, B JOIN C 
onclause, it's not a good practice to structure the statement like that in 
the first place and the Query object has enough complexity going on just to 
keep track of a single chain of joins.   You can structure a statement like 
that with plain select() and join() constructs though, not sure what query 
planners will think of it.

 
 E.g. the join() could raise an error instead of silently throwing the first 
 part of the FROM clause away.  (OTOH, I don't see why the latter has to 
 happen 
 in the first place.)

OK so that part I'm a little curious about as well, from what I recall I didn't 
quite see what aspect would be removing the A from the FROM clause as the 
join() you added didn't specify A as the left side in the usual way, so a 
short test case that is actually runnable and illustrates a working model would 
be of help here.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Mandatory fields in tables referencing each other

2013-01-30 Thread Michael Bayer

On Jan 30, 2013, at 5:00 AM, Matteo wrote:

 Hello everybody,
 
 I'm currently using PostgreSQL 8.4.9 and SQLAlchemy 0.7.9, and there's an 
 issue I just can't seem to solve.
 There are 2 tables, User and People. The idea behind this is to have User's 
 people_id column point to that user's personal data, and People's user_id 
 point to the user who created that person. Neither field can be NULL. This 
 creates an obvious circular dependency when inserting the very first user and 
 its personal data, hence the use of post_update and use_alter.
 Each schema is in a separate file, so they can't import each other. These are 
 their structures:
 
 class User(DeclarativeBase):
 __tablename__ = 'user'
 id = Column(Integer,autoincrement=True,primary_key=True)
 people_id = Column(Integer, ForeignKey('people.id', use_alter=True, 
 name='alter_people_id'), nullable=False, unique=True)
 logname = Column(Unicode(200), unique=True)
 password = Column(Unicode(128))
 
 people = relation(People, primaryjoin = People.id == people_id, 
 post_update=True)
 
 
 
 class People(DeclarativeBase):
 __tablename__ = people
 id = Column(Integer, autoincrement=True, primary_key=True)
 name = Column(Unicode(128))
 [...]
 user_id = Column(Integer, ForeignKey('user.id', use_alter=True, 
 name='alter_user_id'), nullable=False)


both of the foreign key columns are nullable=False.  this creates an impossible 
situation, SQL-wise, as only one row can be added at a time.  The row that goes 
in first necessarily needs to have the FK column be NULL, until the second row 
can go in and the UPDATE statement can set it to something.

  

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Session identity map and PyPy

2013-01-30 Thread Michael Bayer

On Jan 30, 2013, at 5:43 AM, George Sakkis wrote:

 Hello,
 
 I am in the process of migrating to PyPy and have a handful of unit test 
 failing due to the different garbage collector and SQLAlchemy's usage of weak 
 references in the Session identity map. Most failures are probably safe to 
 ignore and all of them are fixed after manually calling gc.collect() 
 somewhere in the test. 

this is true but FTR we do have a pypy suite up on jenkins.sqlalchemy.org, we 
don't run it often because it takes hours, but we did go through lots of effort 
to ensure that all the tests pass, and those that just really need cPython's GC 
are skipped.  Unless you're referring to your own tests.

 
 One specific failure though looks more worrying: a Session.rollback() call in 
 the test's tearDown() method raises InvalidRequestError: Can't attach 
 instance `X`; another instance with key (class `X`, (8L, 1L)) is already 
 present in this session. Before digging deeper, any idea on why it is 
 triggered here and not in any other test?

it would be impossible to say without specific details and examples.   
Generally there is probably some logic that relies upon an X(8, 1) being 
garbage collected from the Session (note the identity map is weak referencing) 
so that an add() later on can succeed.   An add() inside of a tearDown() is 
kind of strange, though, the stack trace would tell you how it's getting there.


 Is there another/better way to prevent it other than calling gc.collect() 
 before Session.rollback() (and perhaps other Session operations)? 

I'd make sure the tests use a brand new Session for every test that's clean.

 
 More generally, are there any other known issues and caveats of running 
 SQLAlchemy on PyPY? 

Our own test suite has a lot of performance issues with Pypy, not sure if due 
to memory or JIT crunching or what, I reported it to their bug tracker at the 
request of their developers.



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Vraj Mohan
Is there any interest in having this fixed? I am new to SQLAlchemy and
am keen to learn both SQLAlchemy and Sphinx, and have some time to
spare. If there's not much interest in the PDFs, I am open to help in
other areas.

--Vraj

On Wed, Jan 30, 2013 at 9:41 AM, Michael Bayer mike...@zzzcomputing.com wrote:
 the PDFS have generated very poorly for quite some time and readthedocs
 environment is not able to adapt to the many warnings it generates for
 SQLAlchemy's documentation.   I've was n the Sphinx list a few years ago at
 this point asking for solutions regarding some of these warnings and was not
 able to get help on them - some of the constructs that Sphinx allows (and
 which we really need, namely code examples underneath a :param:) aren't
 compatible with their LaTeX model.I don't have the resources personally
 to keep banging my head against the immensely antiquated LaTeX tools, not to
 mention readthedocs not getting around to fixing things either, so I've
 taken the PDF links off the site.




 On Jan 30, 2013, at 2:50 AM, Vraj Mohan wrote:

 Hi,

 I noticed that documents in PDF for 0.8 and development are not being
 generated in readthedocs.org.

 I tried to build these myself with a development snapshot and had the same
 failures.

 I then noticed that if a pickled environment was already created, the PDF
 would be generated fine. In other words, make pickle, make html, etc
 would create a pickled environment which would then cause make latexpdf to
 succeed.

 I am not an expert on Sphinx - I thought this would be useful information
 for someone more knowledgeable than me.

 --Vraj Mohan

 --
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.




 --
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Mandatory fields in tables referencing each other

2013-01-30 Thread Matteo
Alright, many thanks.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Werner

On 30/01/2013 17:53, Michael Bayer wrote:

On Jan 30, 2013, at 10:10 AM, Vraj Mohan wrote:


Is there any interest in having this fixed?


I'd love someone to take it on and fix it, sure.I've been asking around for 
help for years, as I still see people publishing entire books with LaTeX.

What about rst2pdf instead of going via LaTex?

http://techtonik.rainforce.org/2010/05/sphinx-pdf-with-rst2pdf.html

I used on smallish docs, so don't know how it will do with SQLAlchemy.

Werner

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Michael Bayer
Keep in mind were ideally working with readthedocs standard tools.  It really 
should be possible for this to all work using standard approaches.

Sent from my iPhone

On Jan 30, 2013, at 12:50 PM, Werner werner.bru...@sfr.fr wrote:

 On 30/01/2013 17:53, Michael Bayer wrote:
 On Jan 30, 2013, at 10:10 AM, Vraj Mohan wrote:
 
 Is there any interest in having this fixed?
 
 I'd love someone to take it on and fix it, sure.I've been asking around 
 for help for years, as I still see people publishing entire books with LaTeX.
 What about rst2pdf instead of going via LaTex?
 
 http://techtonik.rainforce.org/2010/05/sphinx-pdf-with-rst2pdf.html
 
 I used on smallish docs, so don't know how it will do with SQLAlchemy.
 
 Werner
 
 -- 
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Wichert Akkerman

On Jan 30, 2013, at 17:53 , Michael Bayer mike...@zzzcomputing.com wrote:
 I've asked people before about this seemingly ridiculous generate twice 
 requirement of LaTeX and I get these incredulous answers like why? what's 
 wrong with running it twice?, as though I'm being unreasonable.

It is an artefact if how TeX works: it makes a single pass over your document, 
so if it is missing something that is defined later, like TOC entries, it can't 
fill them in and skips them. It does write status files during processing so 
that a later run will have the missing information. In some case you may even 
need to run it more than two times to get page number references to stabilise. 
This strategy was probably an excellent choice in the late 70s / early 80s when 
TeX was created and memory was a scarce resource.

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] Docs in PDF are not being generated

2013-01-30 Thread Gery .
Standardization is always necessary, just a question, which tool would you 
suggest for converting things to PDF?

Sent from my iBath

On Jan 30, 2013, at 20:16, Michael Bayer mike...@zzzcomputing.com wrote:

Keep in mind were ideally working with readthedocs standard tools.  It really 
should be possible for this to all work using standard approaches.

Sent from my iPhone

On Jan 30, 2013, at 12:50 PM, Werner werner.bru...@sfr.fr wrote:

 On 30/01/2013 17:53, Michael Bayer wrote:
 On Jan 30, 2013, at 10:10 AM, Vraj Mohan wrote:
 
 Is there any interest in having this fixed?
 
 I'd love someone to take it on and fix it, sure.I've been asking around 
 for help for years, as I still see people publishing entire books with LaTeX.
 What about rst2pdf instead of going via LaTex?
 
 http://techtonik.rainforce.org/2010/05/sphinx-pdf-with-rst2pdf.html
 
 I used on smallish docs, so don't know how it will do with SQLAlchemy.
 
 Werner
 
 -- 
 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?hl=en.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] Tracking changes made to mapped objects

2013-01-30 Thread rurpy
I'm using Sqlalchemy for the first time and am slowly 
figuring out most of what I need.  However there is one
aspect I would like some advice about.

I have a GUI program that gets some number of items (say
data about movies for example) from a database and lets 
the user edit them including foreign key linked table 
data like directors or actors.

My question is how to track changes.  A user may change
some attribute of a movie (or of one of the subtables 
linked to it), say the year made, then page to a different
movie, and change something there.  Such changes are 
reflected in the session.dirty, session.new and 
session.deleted properties for a while (up to some point 
where Sqlalchemy decides it needs to do a flush).  But 
after a flush, the .dirty (et.al.) properties no longer 
show anything but the changes are still not permanent 
since no commit has been done yet.

I need to indicate in the GUI *what* mapped objects 
and what attributes of those objects have been changed, 
perhaps by displaying values in red (for example) to 
allow the user to review or revert changes before 
saving (i.e. committing). 

How can I determine what has been changed, even after 
a flush?  (Or should I disable autoflushing?)

How to revert some changes (but not all; for that I 
would just do a rollback, yes?)

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] joinedload on inherited class causing subquery instead of raw joins?

2013-01-30 Thread Gerald Thibault
I have a user object, and an extended user object which inherits from the 
base user object. I also have a test object, which has a FK to the extended 
user object. When I try this:

res = session.query(Test) \
.options(joinedload('user')) \
.all()

I see this sql generated:

SELECT test.id AS test_id, test.user_id AS test_user_id, 
anon_1.users_ext_id AS anon_1_users_ext_id, anon_1.users_id AS 
anon_1_users_id 
FROM test LEFT OUTER JOIN (SELECT users.id AS users_id, users_ext.id AS 
users_ext_id 
FROM users JOIN users_ext ON users.id = users_ext.id) AS anon_1 ON 
anon_1.users_ext_id = test.user_id

there are no limits or constraints on the subquery, so this takes a 
nightmarish amount of time to resolve (hundreds of thousands of users in 
the table), while the query i was expecting works instantly. The query I am 
trying to achieve is:

SELECT test.id AS test_id, test.user_id AS test_user_id, 
anon_1.users_ext_id AS anon_1_users_ext_id, anon_1.users_id AS 
anon_1_users_id 
FROM test 
LEFT OUTER JOIN users_ext ON users_ext.id = test.user_id
JOIN users ON users_ext.id = users.id

How can I generate the second query instead of the first? It seems like all 
the parts are there, but put together in a terrible way that ensures it 
will take the maximum amount of time to resolve.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


from sqlalchemy import *
from sqlalchemy.orm import relation, joinedload, create_session
from sqlalchemy.ext.declarative import declarative_base

e = create_engine('sqlite:tmp/foo.db', echo=True)
Base = declarative_base(bind=e)

class User(Base):
__tablename__ = 'users'

id = Column(Integer, primary_key=True)

class UserExtension(User):
__tablename__ = 'users_ext'

id = Column(Integer, ForeignKey(User.id), primary_key=True)

class Test(Base):
__tablename__ = 'test'

id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey(UserExtension.id))
user = relation(UserExtension, lazy=True)

Base.metadata.drop_all()
Base.metadata.create_all()

session = create_session(bind=e)
res = session.query(Test) \
.options(joinedload('user')) \
.all()


SELECT test.id AS test_id, test.user_id AS test_user_id, anon_1.users_ext_id AS anon_1_users_ext_id, anon_1.users_id AS anon_1_users_id 
FROM test LEFT OUTER JOIN (SELECT users.id AS users_id, users_ext.id AS users_ext_id 
FROM users JOIN users_ext ON users.id = users_ext.id) AS anon_1 ON anon_1.users_ext_id = test.user_id