Re: [sqlalchemy] How to use multiple foreign keys as composite primary key in sqlalchemy?

2014-07-15 Thread Simon King
, primary_key=True) I'm not sure I understand the question. I don't think you need the UniqueConstraint at all - by putting primary_key=True on both columns, the pairing is guaranteed to be unique anyway. Simon -- You received this message because

Re: [sqlalchemy] Is it considered bad practice to have more than one session instance simultaneously in a web application?

2014-07-14 Thread Simon King
is fairly small. If you've come up with a solution that works for you, carry on :-) Hope that helps, Simon On Mon, Jul 14, 2014 at 12:07 PM, Bao Niu niuba...@gmail.com wrote: Thank you guys for your replies. These days I spent some time reading the documentation on session to make sure I

Re: [sqlalchemy] how can i get .engine.execute result?

2014-07-04 Thread Simon King
On Fri, Jul 4, 2014 at 6:54 AM, 'Frank Liou' via sqlalchemy sqlalchemy@googlegroups.com wrote: Hi Simon thanks for your answer but i can't understand what's fetchall() mean i remove the fetchall() it still work This is because the ResultProxy returned from conn.execute() is what

Re: [sqlalchemy] Is it considered bad practice to have more than one session instance simultaneously in a web application?

2014-06-30 Thread Simon King
I'm not sure I understand your application. Are you saying that you have Person instances that stay in memory for longer than a single web request? Simon On Sun, Jun 29, 2014 at 11:54 AM, Bao Niu niuba...@gmail.com wrote: Hi Mike, Thanks for your reply. In my case, the full_name attribute

Re: [sqlalchemy] Is it considered bad practice to have more than one session instance simultaneously in a web application?

2014-06-30 Thread Simon King
. As far as I'm concerned, hybrid_property is just a convenient mechanism to help you avoid writing self.FirstName + ' ' + self.LastName everywhere, even in queries) Simon On Mon, Jun 30, 2014 at 11:28 AM, Bao Niu niuba...@gmail.com wrote: Hi Simon, Sorry for the poor explanation in my previous post

Re: [sqlalchemy] hybrid_properties and literals

2014-06-20 Thread Simon King
, such as the JSON example in the docs: http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#marshal-json-strings Hope that helps, Simon -- 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

Re: [sqlalchemy] How to do a query on a returned object?

2014-06-18 Thread Simon King
to the person instance. You would use it like: name_query = p.names_collection.filter(Names.name.startswith('B')) This usually only makes sense for very large collections, since you can't really eager-load a dynamic relationship. Hope that helps, Simon -- You received this message because you

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/declarative.html#accessing-the-metadata Hope that helps, Simon -- 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

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
In that case, could you send a stripped-down single-file test case with just those 2 classes that shows the problem? Thanks, Simon On Thu, Jun 12, 2014 at 5:13 PM, ty...@beanfield.com wrote: I have tried calling relationship without foreign_keys or primaryjoin, in which case I get an error

Re: [sqlalchemy] relationship issues

2014-06-12 Thread Simon King
='all, delete-orphan')) if __name__ == '__main__': engine = create_engine('sqlite://', echo='debug') Session = sessionmaker(bind=engine) Base.metadata.create_all(bind=engine) On Thu, Jun 12, 2014 at 5:19 PM, Simon King si...@simonking.org.uk wrote: In that case, could you send

Re: [sqlalchemy] Sub-classing declarative classes

2014-06-11 Thread Simon King
): setattr(cls, f.__name__, f) return patcher @monkeypatch(some_model.Alice) def myfunc(self): do_nothing_sql_related_here() (This is pretty nasty really, but depending on your requirements it might be the easiest way to make it work) Hope that helps, Simon -- You received

Re: [sqlalchemy] Triggers with sqlite

2014-05-08 Thread Simon King
(trigger).execute(bind=engine) for x in 'UPDATE', 'INSERT', 'DELETE': event.listen(Foo.__table__, after_create, make_handler(x, engine)) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group

Re: [sqlalchemy] Best way to set up sqlite_pragma for all applications

2014-05-06 Thread Simon King
foreign_keys=ON) cursor.close() def enable_sqlite_foreign_keys(): sqlalchemy.event.listen(sqlalchemy.engine.Engine, 'connect', _set_sqlite_pragma) ...and then call the enable_sqlite_foreign_keys function somewhere in your application setup code. Hope that helps, Simon -- You received

Re: [sqlalchemy] Error querying stored values

2014-04-29 Thread Simon King
without getting this error? I've never used oracle with sqlalchemy before, but looking at the bottom of the stack trace, is it possible that you have declared your column as some sort of BLOB type but it is actually a simpler data type in the database? Hope that helps, Simon -- You received

Re: [sqlalchemy] Commit question

2014-04-17 Thread Simon King
, relationship_type=marriage)) martha.relationships [] session.commit() [Relationship Washington, Martha Washington, George (Marriage)] What do your mappings look like for the classes in question? Simon -- You received this message because you are subscribed to the Google Groups

Re: [sqlalchemy] query returns sqlalchemy.util._collections.KeyedTuple. not a maped class instance

2014-04-15 Thread Simon King
= q.filter(tblKey2goGdataLocation.id == 123) result = q.first() Hope that helps, Simon -- 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

Re: [sqlalchemy] Is it possible to create a filter 'string' LIKE column + '%'?

2014-04-10 Thread Simon King
You can also use sqlalchemy.literal, which returns an object that you can treat like a column: sqlalchemy.literal('string').like('whatever') You may also be interested in the 'startswith' shortcut, which calls .like under the hood sqlalchemy.literal('string').startswith(yourcolumn) Simon

Re: [sqlalchemy] Error: ORA-01036: illegal variable name/number

2014-04-03 Thread Simon King
here? It opens you up to bugs and possibly sql injection attacks if you don't quote your strings properly. For example, what happens if tmm_id contains a single quote? Cheers, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from

Re: [sqlalchemy] Modifying a cascaded object directly and then saving its parent

2014-04-03 Thread Simon King
example to work because you are attaching the freshly loaded child instance to a parent which is no longer associated with a session. What happens in your test if you reload the parent instance first? Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy

Re: [sqlalchemy] is it possible to eagerload a specific collection on a loaded object ?

2014-04-02 Thread Simon King
(model.User) .filter_by(id=1) .options(joinedload('foo'), joinedload('foo.bar')) .first()) This will join to the User table and fetch all its columns - I don't know if there's an easy way to avoid that. Simon -- You received this message because you

Re: [sqlalchemy] is it possible to eagerload a specific collection on a loaded object ?

2014-04-02 Thread Simon King
= session.query(cls) condition = [] for col, val in zip(primary_key, identity): condition.append(col == val) query = query.filter(sa.and_(*condition)) return query u = session.query(User).get(1) get_query(u).options(joinedload_all('foo.bar')).first() Simon -- You received

Re: [sqlalchemy] Self-join and autoload

2014-03-28 Thread Simon King
' __table_args__ = {'autoload':True, 'schema':'sdssphoto'} PhotoObj.children = relationship(PhotoObj, backref=backref('parent', remote_side=[PhotoObj.pk])) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group

Re: [sqlalchemy] Best sql platform to use with sqlalchemy on a limited shared network

2014-03-28 Thread Simon King
pass the appropriate filesystem path to SQLAlchemy. Examples are at http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#connect-strings Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group

Re: [sqlalchemy] What are the ORM mechanics when appending a new association in an M to N relationship?

2014-03-27 Thread Simon King
= Appointment(appointment_user_relation=user) # Association proxy does this: appointment.meeting_appointment_relation = meeting Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop

Re: [sqlalchemy] What is the rationale of having to manually set up a relationship between two tables?

2014-03-25 Thread Simon King
I would say that the extension is intended to replace SqlSoup in the future, but may not be ready for that quite yet. Simon On Tue, Mar 25, 2014 at 12:39 AM, Bao Niu niuba...@gmail.com wrote: Compare to SQLsoup, is this extension more recommended? On Mon, Mar 24, 2014 at 3:32 AM, Simon King

Re: [sqlalchemy] session and thread confusion

2014-03-25 Thread Simon King
after a commit or abort) Hope that helps, Simon -- 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

Re: [sqlalchemy] What is the rationale of having to manually set up a relationship between two tables?

2014-03-24 Thread Simon King
., leaving out the red part? Will this feature likely be included in future versions, say, sqlalchemy 1.0? You might be interested in the experimental automap extension: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/automap.html Hope that helps, Simon -- You received this message

Re: [sqlalchemy] after_delete callback doesn't being called with query(...).delete() syntax

2014-03-24 Thread Simon King
You'd probably have to examine the delete_context.query object to see which class is being deleted, and figuring out exactly which rows have been deleted might also be a problem (since the filter conditions passed to the query could be arbitrarily complicated). Simon -- You received this message

Re: [sqlalchemy] Re: Best practice for binding the engine

2014-03-13 Thread Simon King
to switch. And you can trust that the Session will use the bindings established on the metadata, if it is not explicitly bound itself. Simon On Thu, Mar 13, 2014 at 7:48 AM, Bao Niu niuba...@gmail.com wrote: Hi Simon, I've got a follow-up question regarding the best practice. You seem to favour

Re: [sqlalchemy] Re: Best practice for binding the engine

2014-03-12 Thread Simon King
on a per-session basis which engine you want to use (for example if you had different engines for read and write access). Hope that helps, Simon On Wed, Mar 12, 2014 at 7:25 AM, Bao Niu niuba...@gmail.com wrote: Ok, let me try rephrasing my question. Is binding an engine/connection simultaneously

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-03-03 Thread Simon King
On Mon, Mar 3, 2014 at 7:55 AM, Chris Withers ch...@simplistix.co.uk wrote: Hi Simon, On 26/02/2014 13:18, Simon King wrote: I don't know exactly what your needs are, but here's the example from the docs: engine1 = create_engine('postgresql://db1') engine2 = create_engine

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Simon King
/PreFilteredQuery Simon -- 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

Re: [sqlalchemy] How to automatically handle deletion flags

2014-02-27 Thread Simon King
://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#mapping-a-class-against-arbitrary-selects The docs discourage mapping to a select because of the complexity of the resulting queries, but in your case perhaps those queries are exactly what is required. Hope that helps, Simon On Thu, Feb 27, 2014 at 1:06

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-02-26 Thread Simon King
() method: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.get_bind http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#sqlalchemy.orm.session.Session.params.binds Would that work in your situation? Simon On Wed, Feb 26, 2014 at 12:50 PM, Chris Withers ch

Re: [sqlalchemy] How is 'all connections returned to the connection pool' implemented?

2014-02-25 Thread Simon King
, and I'm always glad when I see a question I can actually answer ;-) Simon -- 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

Re: [sqlalchemy] Update a parameter based on input in sqlalchemy

2014-02-25 Thread Simon King
: status_args = {trans_status: 1} status = Status(**status_args) new_trans = Transaction(date=cur_date, status=status) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from

Re: [sqlalchemy] tying multiple sessions together with one transaction

2014-02-25 Thread Simon King
I've never used two-phase commit, but can you get away with just a single session, like the example at: http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#enabling-two-phase-commit Simon On Tue, Feb 25, 2014 at 6:07 PM, Chris Withers ch...@simplistix.co.uk wrote: No takers

[sqlalchemy] Problem with Boolean columns, NULL and Versioned example

2014-02-24 Thread Simon King
]) sc.name = 'sc1modified2' sc.somebool = True session.commit() checkhistory([False, None]) if __name__ == '__main__': test() Thanks in advance for any help, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe

Re: [sqlalchemy] How to verify an object is in database? How to compare objects by values?

2014-02-24 Thread Simon King
. This is more complicated given that you want to compare related objects as well, but perhaps it would be fine if you were to query the primary object (eg. User in your example above) and then allow SA to load the associated Addresses automatically. Hope that helps, Simon -- You received this message

Re: [sqlalchemy] Could anyone please help explain expired object in plain language?

2014-02-24 Thread Simon King
you have expired objects whose state is newer than the database? Cheers, Simon On Mon, Feb 24, 2014 at 12:06 PM, Bao Niu niuba...@gmail.com wrote: Sorry for my slowness, but I still have a minor problem understanding expired object. Why does it always assume that the database carries the most

[sqlalchemy] Re: Problem with Boolean columns, NULL and Versioned example

2014-02-24 Thread Simon King
On Mon, Feb 24, 2014 at 12:01 PM, Simon King si...@simonking.org.uk wrote: Hi, I'm using the Versioned class from the examples, and I noticed that when I set a Boolean column to None (NULL in the db), the eventual history row corresponding to that change gets a 0 rather than a NULL

Re: [sqlalchemy] How to verify an object is in database? How to compare objects by values?

2014-02-24 Thread Simon King
it might be more complicated, but I don't use Python 3 so I can't really help you.) If you are using Python 2 and the strings don't compare equal, perhaps you have an incorrect encoding defined somewhere? Simon On Mon, Feb 24, 2014 at 12:59 PM, marcin.rafal.adam...@gmail.com wrote: I've tried

Re: [sqlalchemy] Problem with Boolean columns, NULL and Versioned example

2014-02-24 Thread Simon King
would only be used if I never set the attribute at all. Does this mean that there's no way through the ORM to insert a new row with NULLs for columns that have been assigned a default value? (Just an idle question, not something I need). Thanks again, Simon On Mon, Feb 24, 2014 at 5:31 PM, Michael

Re: [sqlalchemy] What is the point to re-define each and every column in __init__ in a class?

2014-02-10 Thread Simon King
-of-the-mapped-class Hope that helps, Simon -- 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

Re: [sqlalchemy] Session remove/close MySQL

2014-02-07 Thread Simon King
you can use to control how the pool works. See the docs at http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from

Re: [sqlalchemy] SQLite: OperationalError when decoding 0x92 in TEXT column

2014-02-04 Thread Simon King
I've not done much with reflection, but perhaps you could use the column_reflect event: http://docs.sqlalchemy.org/en/rel_0_8/core/events.html#sqlalchemy.events.DDLEvents.column_reflect Simon On Tue, Feb 4, 2014 at 11:28 AM, Erich Blume blume.er...@gmail.com wrote: Thanks Simon, Do you

Re: [sqlalchemy] joinedload options on a query don't affect its .count()?

2014-01-29 Thread Simon King
, and I had to set uselist=False on the a.b backref. If you get different results, what version of SA are you using? Simon On 28 Jan 2014, at 17:45, Michael Nachtigal michael.nachti...@catalinamarketing.com wrote: Simon, Thanks very much for your detailed reply. Here's your example tailored

Re: [sqlalchemy] Versioned object example

2014-01-25 Thread Simon King
Oh, yes, of course, I forgot that foreign keys aren’t immediately updated when you manipulate a relationship. Your suggested change sounds exactly right. Thanks again, Simon On 25 Jan 2014, at 02:30, Michael Bayer mike...@zzzcomputing.com wrote: well since create_version() is called

Re: [sqlalchemy] Relationship with complicated join conditions

2014-01-24 Thread Simon King
On Thu, Jan 23, 2014 at 7:46 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 23, 2014, at 2:07 PM, Simon King si...@simonking.org.uk wrote: That's fantastic, thanks so much. I feel bad that my silly use case has caused so much work for you and grown the docs even more (perhaps you

[sqlalchemy] Versioned object example

2014-01-24 Thread Simon King
: if p.foreign_keys: obj_changed = True break if obj_changed is True: break I can't figure out the circumstances when this should be necessary - can someone explain it to me? Thanks a lot, Simon

[sqlalchemy] Re: Versioned object example

2014-01-24 Thread Simon King
On Fri, Jan 24, 2014 at 4:22 PM, Simon King si...@simonking.org.uk wrote: Hi again, While testing the complicated relationship from the other thread, I noticed that I was generating a lot of queries that I couldn't immediately explain. After a bit of digging, it turned out that it was due

Re: [sqlalchemy] joinedload options on a query don't affect its .count()?

2014-01-24 Thread Simon King
=== count = 3 len(results) = 1 1. __main__.A object at 0x10b8bf9d0 The second and fourth tests are the same as the first and third with a joinedload(‘cs’) added. In both cases, the results remain the same. Cheers, Simon On 24 Jan 2014, at 22:36, Michael Nachtigal michael.nachti

Re: [sqlalchemy] Relationship with complicated join conditions

2014-01-23 Thread Simon King
On Thu, Jan 23, 2014 at 1:45 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 22, 2014, at 7:17 PM, Simon King si...@simonking.org.uk wrote: I read the bit in the docs about non-primary mappers but was scared off by the almost never needed warnings. Actually, for the purposes I'm

Re: [sqlalchemy] Sqlalchemy ORM operates on database not created from sqlalchemy

2014-01-22 Thread Simon King
, session.query(Class), session.add, session.commit .etc Yes, absolutely. SQLAlchemy doesn't care how the database was created. You should be able to use all the normal operations on a database created by some other means. Hope that helps, Simon -- You received this message because you are subscribed

[sqlalchemy] Relationship with complicated join conditions

2014-01-22 Thread Simon King
() or remote(). Thanks for any advice, Simon -- 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

Re: [sqlalchemy] Re: Relationship with complicated join conditions

2014-01-22 Thread Simon King
(), Acceptance.datetime) = 365 If this relationship finds a matching row, the user has accepted the terms in the last year. But if no row matches, the user must re-accept. I'll work up the test script tomorrow to clarify. Thanks, Simon -- You received this message because you are subscribed to the Google

Re: [sqlalchemy] Sqlalchemy ORM operates on database not created from sqlalchemy

2014-01-22 Thread Simon King
, Simon On 22 Jan 2014, at 23:35, Ni Wesley nisp...@gmail.com wrote: I mean sqlalchemy ORM, that is, use python class mapping to database table. I know sqlalchemy core expression does work, this guy doesn't care how database is created. Wesley 2014年1月22日 下午7:04于 Simon King si...@simonking.org.uk写道

Re: [sqlalchemy] Relationship with complicated join conditions

2014-01-22 Thread Simon King
On 22 Jan 2014, at 23:45, Michael Bayer mike...@zzzcomputing.com wrote: On Jan 22, 2014, at 11:54 AM, Simon King si...@simonking.org.uk wrote: Hi all, I've been having a little trouble configuring a relationship between 2 mapped classes where the join condition pulls in another 2 tables

Re: [sqlalchemy] Using flask-sqlalchemy BaseQuery and Pagination with multiple tables.

2014-01-08 Thread Simon King
in using load_only instead: http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#load-only-cols which is part of a bigger topic about deferred column loading: http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#deferred-column-loading Hope that helps, Simon -- You received

Re: [sqlalchemy] Struggling with a join

2013-11-29 Thread Simon King
(s) for row in result: print row Applying filter conditions to a Select object is described at http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#selecting. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group

Re: [sqlalchemy] Re: Struggling with a join

2013-11-29 Thread Simon King
the examples at http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#using-joins Hope that helps, Simon On Fri, Nov 29, 2013 at 2:46 PM, Glenn Wilkinson glenn.wilkin...@gmail.com wrote: Hi Simon, Thanks for the reply. I've been using sqlalchemy fine with other queries not using a join

Re: [sqlalchemy] SQLSoup, whitespace

2013-11-16 Thread Simon King
) Are there any cool tricks I don't know? Thanks How about: values = {‘XML Schema Version’: None} db.table.insert(**values) Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving

Re: [sqlalchemy] using Column.in_(a_large_list) is very slow.

2013-11-15 Thread Simon King
bind parameters work, each id needs a separate parameter. Is it important that you get the results all in one go? Could you try processing the ids in smaller batches, perhaps 100 or so at a time? Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group

Re: [sqlalchemy] add foreign key constraint

2013-11-14 Thread Simon King
? The docstring says that it creates a sqlalchemy.schema.Table object, but I read that as just an implementation detail - I don't think a new table should end up in the database. Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from

Re: [sqlalchemy] Am I doing it wrong?

2013-11-06 Thread Simon King
far. How you proceed from here really depends on how you application is going to use the data in this database. Cheers, Simon -- 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

Re: [sqlalchemy] Relationship id not set automatically?

2013-11-06 Thread Simon King
: these attributes aren't changed until you call session.flush() Simon -- 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

Re: [sqlalchemy] Process guide - XML

2013-10-31 Thread Simon King
with the data. Hope that helps, Simon -- 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

Re: [sqlalchemy] Session Management Issues While Integrating With Old Code

2013-10-04 Thread Simon King
than n seconds. Hope that helps, Simon -- 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

Re: [sqlalchemy] Query for date between a range

2013-10-04 Thread Simon King
I'm not sure that will work on it's own, will it? When used in a class context (Plan.calculated_date), you will end up calling the date function with 3 SQLAlchemy column objects, which won't work. At a minimum, you'd need this: class Plan(Base): @hybrid_property def

Re: [sqlalchemy] sqlalchemy postgresql error

2013-09-26 Thread Simon King
question, but have you installed the psycopg2 package (https://pypi.python.org/pypi/psycopg2)? SQLAlchemy doesn't include the low-level database drivers - you have to install the appropriate driver for the database you are using. Hope that helps, Simon -- You received this message because you

Re: [sqlalchemy] Create Table scripts failing randomly - scripts work from sqlite3 driver but not sqlalchemy

2013-09-23 Thread Simon King
loading of data, you could look at the examples at http://docs.sqlalchemy.org/en/rel_0_7/core/tutorial.html#executing-multiple-statements Simon On Mon, Sep 23, 2013 at 6:54 AM, monosij.for...@gmail.com wrote: Hi Simon - Great! The executescript from sqlite worked great. I had not seen that. I

Re: [sqlalchemy] Create Table scripts failing randomly - scripts work from sqlite3 driver but not sqlalchemy

2013-09-22 Thread Simon King
will be the same. I think you need to find a way to split your scripts up into individual statements that you can run one at a time. Hope that helps, Simon On 21 Sep 2013, at 16:14, monosij.for...@gmail.com wrote: Hi Michael and Simon - Thank you for your responses and help. Sorry I should

Re: [sqlalchemy] Create Table scripts failing randomly - scripts work from sqlite3 driver but not sqlalchemy

2013-09-20 Thread Simon King
() so that your script aborts after an exception. Simon -- 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

Re: [sqlalchemy] dynamic query with many parametters

2013-09-08 Thread Simon King
WHERE name LIKE '%Mohsen%' AND phonenumber LIKE '%1%' Is that the sort of SQL that you are hoping to see, or do you need something different? Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-06 Thread Simon King
on which connections. When the error occurs, look at all the SQL sent on that connection and perhaps you will see what is causing the problem. On 6 Sep 2013, at 21:42, herzaso herz...@gmail.com wrote: Hi Simon, I've removed the scoped_session altogether but the problem still persists

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-05 Thread Simon King
at http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#sqlalchemy.orm.scoping.scoped_session), or you could get rid of scoped sessions altogether, and instead create a session at the beginning of a request and pass it to your handler functions (or attach it to the Request object). Simon On Thu

Re: [sqlalchemy] query question

2013-09-04 Thread Simon King
(Person.name).filter(Person.age 100).first() You can also defer certain columns so that they will be loaded lazily: http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html#deferred-column-loading Hope that helps, Simon -- You received this message because you are subscribed to the Google

Re: [sqlalchemy] error related to setting attribute to same value twice

2013-09-03 Thread Simon King
not quite the same as your error message. What version of SQLAlchemy are you using? (The above was from 0.8.2) Simon On Tue, Sep 3, 2013 at 10:15 AM, lars van gemerden l...@rational-it.com wrote: I am getting that same error (not the original one). For the moment i've solved the problem in a different

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-03 Thread Simon King
with this issue... not only do I feel helpless, I don't have any clue on how to get around it ... What if I make the change without the session? Would the session pick up the changes on its first query? On Monday, September 2, 2013 3:58:02 PM UTC+3, Simon King wrote: I'm no expert on isolation

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-03 Thread Simon King
logged-in users) what are the odds that the same user will get the same error 10 times? On 3 Sep, 2013 3:05 PM, Simon King si...@simonking.org.uk wrote: Race conditions can happen at any time, not just when the system is under heavy load. You only need 2 requests to arrive at approximately

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-03 Thread Simon King
- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Simon King Sent: Tuesday, September 03, 2013 3:28 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID OK, I agree that doesn't sound like

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-02 Thread Simon King
other constraint in the database? Simon On Mon, Sep 2, 2013 at 8:45 AM, herzaso herz...@gmail.com wrote: I'm afraid it didn't solve my problem. Here is my updated method: @classmethod def get(cls, bar=None, baz=None, qux=None, **kwargs): query = session.query(cls

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-02 Thread Simon King
has inserted a matching row in the meantime. Simon On Mon, Sep 2, 2013 at 12:54 PM, herzaso herz...@gmail.com wrote: I'm not sure what to make of the results: On the first connection, I ran BEGIN and INSERT and both were successful, but when I tried the INSERT statement on the second connection

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-02 Thread Simon King
have it set as REPEATABLE READ. However, I don't use transactions in sqlalchemy On Monday, September 2, 2013 3:08:58 PM UTC+3, Simon King wrote: Do you know what transaction isolation level you are running at? The default apparently is REPEATABLE READ: http://dev.mysql.com/doc/refman/5.6/en

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-02 Thread Simon King
, dealing with concurrent operations is hard, and SQLAlchemy isn't going to magically make it any easier I'm afraid. Simon On Mon, Sep 2, 2013 at 1:40 PM, herzaso herz...@gmail.com wrote: I'm sorry, it was a misunderstanding on my part regarding the transactions. So what are you saying? that I should

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-09-02 Thread Simon King
it a try with a session.close to see if it helps (although I think I had complaints from users running the same API several times - and each time, at the end of my REST APIs I run session.close) On Monday, September 2, 2013 3:58:02 PM UTC+3, Simon King wrote: I'm no expert on isolation levels - I

Re: [sqlalchemy] error related to setting attribute to same value twice

2013-09-02 Thread Simon King
violate that assumption (eg. by loading one instance of person from the database, then creating another instance and setting its primary key), you will get errors like this. Does that sound plausible? Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy

Re: [sqlalchemy] error related to setting attribute to same value twice

2013-09-02 Thread Simon King
in diagnosing the problem. Simon On 2 Sep 2013, at 18:56, Lars van Gemerden l...@rational-it.com wrote: Well, from the message yes, but i am not setting any primary keys manually, so where could the second instance come from? CL Lars van Gemerden l...@rational

Re: [sqlalchemy] error related to setting attribute to same value twice

2013-09-02 Thread Simon King
is to use session.merge to create a copy of the object, attached to the new session. If you change the last few lines of the script above to: sess2 = Session() merged = sess2.merge(person) sess2.add(merged) ...it works fine. Hope that helps, Simon On 2 Sep 2013, at 19:58, lars van

Re: [sqlalchemy] an unkown object in code.

2013-09-01 Thread Simon King
it from your mapped class via the __table__ attribute, but most of the time you don't need it. Hope that helps, Simon -- 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

Re: [sqlalchemy] sqlalchemy.exc.ArgumentError: Valid strategies for session synchronization are 'evaluate', 'fetch', False

2013-09-01 Thread Simon King
(Seller.name == 'golrang').delete() If you want to use the underlying sellers Table object, it would look something like this: delete_statement = sellers.delete().where(sellers.c.name == 'golrang') session.execute(delete_statement) Hope that helps, Simon PS. note the convention that Table instances

Re: [sqlalchemy] many queries select if in cycle has insert into table

2013-08-30 Thread Simon King
, Simon -- 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

Re: [sqlalchemy] copying data w/o over-writing autoincrement fields

2013-08-29 Thread Simon King
, because the foreign keys will be inserted with their old values rather than the new ones. Fixing that would be much more complicated. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop

Re: [sqlalchemy] watining for table metadata lock

2013-08-29 Thread Simon King
. In answer to your first question, http://dev.mysql.com/doc/refman/5.5/en/metadata-locking.html suggests that non-transactional tables can also be involved in metadata locks. I'm afraid I can't help with the rest. Simon -- You received this message because you are subscribed to the Google Groups

Re: [sqlalchemy] watining for table metadata lock

2013-08-29 Thread Simon King
On Thu, Aug 29, 2013 at 5:20 PM, Simon King si...@simonking.org.uk wrote: On Thu, Aug 29, 2013 at 4:48 PM, diverman pa...@schon.cz wrote: Hi, we observed deadlock-like problem on our multi-component system with mysql database. Our setup: 1) MySQL server 5.5 with many MyISAM tables

Re: [sqlalchemy] watining for table metadata lock

2013-08-29 Thread Simon King
On Thu, Aug 29, 2013 at 6:01 PM, diverman pa...@schon.cz wrote: Dne čtvrtek, 29. srpna 2013 18:23:12 UTC+2 Simon King napsal(a): On Thu, Aug 29, 2013 at 5:20 PM, Simon King si...@simonking.org.uk wrote: On Thu, Aug 29, 2013 at 4:48 PM, diverman pa...@schon.cz wrote: Hi, we observed

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-08-27 Thread Simon King
at the UniqueObject recipe in the wiki: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject Hope that helps, Simon -- 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

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Instance 'MYCALSSTABLENAME at 0x994a90c' is not persisted

2013-08-27 Thread Simon King
, addRecord, createEngine, createSession and so on. SellersTable is class name of sellers table. Where's Problem? It sounds like you are trying to delete an entry which you've never stored in the database. Where are you getting your ddd object from? Simon -- You received this message because

Re: [sqlalchemy] Occasional IntegrityError when identifying model not by its ID

2013-08-27 Thread Simon King
On Tue, Aug 27, 2013 at 2:31 PM, herzaso herz...@gmail.com wrote: On Tuesday, August 27, 2013 3:55:50 PM UTC+3, Simon King wrote: On Tue, Aug 27, 2013 at 1:40 PM, herzaso her...@gmail.com wrote: I have a model with an ID column set as the primary key, though i'd like to be able

Re: [sqlalchemy] Re: sqlalchemy.exc.InvalidRequestError: Instance 'MYCALSSTABLENAME at 0x994a90c' is not persisted

2013-08-27 Thread Simon King
. If you want to avoid the SELECT, you can use the Query.delete() method, something like this: session.query(SellersTable).filter_by(name_type=1).delete() http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.delete Hope that helps, Simon On 27 Aug 2013, at 18:28

<    1   2   3   4   5   6   7   8   9   10   >