[sqlalchemy] Re: sessions and transaction
Michael Bayer ha scritto: if the transaction fails, the session goes right back to the same state that existed before you called the flush(), as though nothing happened. With this example: trans = begin_transaction() session = ctx.current a = SomeObject(...) session.save(a) raise Exception() session.flush() trans.commit() The session will have the a object attached to it, so if another function calls session.flush (in the same thread), the object is created on the database. This is not what I want. Maybe the better solution is to not share sessions at all. Regards Manlio Perillo --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: self-referential table question
Works perfectly. Your responsiveness and the usefulness of SQLAlchemy continue to amaze. Thanks. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] SA 0.3.x: performance issues
Michael Bayer wrote: you need to forward the *actual test program* which you are running. i have tests for performance which generally show very minute speed differences between 0.2 and 0.3. The logging statements can be sped up by making them conditional and maybe removing some. I've noticed that SA is doing a lot of string formatting in logging statements like this: log.debug('%s %s' % ('green', 'apples')) log.debug(( + self.abc + | + self.xyz + ) + msg) The logging package is designed to allow string formatting to be deferred until the log statement is actually written to a log (so it only happens when logging is enabled). Here's how you'd take advantage of that: log.debug('%s %s', 'green', 'apples') log.debug((%s|%s) %s, self.abc, self.xyz, msg) Also, you need to stop writing Perl in Python :) The mapper logging is quite inefficient. Here's a quick example of how that could be improved: class MapperLoggingExample(object): def __init__(self): # ... if logging.is_debug_enabled(self.logger): name = [(, self.class_.__name__, |] if self.entity_name is not None: name.extend([/, self.entity_name]) if self.local_table: name.append(self.local_table.name) else: name.append(self.local_table) if not self._is_primary_mapper(): name.append(|non-primary) name.append() %s) logging_name = .join(name) self.log_fast = lambda msg: self.logger.debug(logging_name, msg) else: self.log_fast = lambda msg: None def log_slow(self, msg): self.logger.debug(( + self.class_.__name__ + | + (self.entity_name is not None and /%s % self.entity_name or ) + (self.local_table and self.local_table.name or str(self.local_table)) + (not self._is_primary_mapper() and |non-primary or ) + ) + msg) # usage example m = MapperLoggingExample() m.log_slow(test message) m.log_fast(test message) According to my tests, log_fast() is about 50 times faster than log_slow() when logging is disabled, and marginally faster when logging is enabled. ~ Daniel --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SA 0.3.x: performance issues
what logging really needs is this: logging.debug(lambda: %s - %s % (_get_data(x),_get_other_data(y)) and the lambda: doesnt execute if logging is disabled; which accounts for a lot more than just doing the % operation or not, such as in my case where i make calls out to _instance_str() to represent an instance string. however, theres still overhead to creating those lambdas. anyway, if you look at what I did, I just set a boolean flag in the constructor based on is_debug_enabled() and just check the flag explicitly before every call to debug()so no method calls or log message construction of any kind happen at all if debug logging is disabled. speed looks a lot more like 0.2.8 now (pending further test cases people want to give me). (the next thing that might help is if i speed up the calls to mapper_extension). also, I challenge your assertion that saying x and y or z is a perlish thing (its a C and Java thing if anything); python 2.5 has just added the y if x else z syntax which is essentially an official version of the same thing. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] pysqlite and time support
Regards. From the code in qlalchemy.databases.sqlite.py it seems that SQLAlchemy does not support things like: 12:30:00.30 That is: seconds with a fractional part. Any reasons for doing this? Manlio Perillo --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: self-referential table question
Works. Thanks. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SA 0.3.x: performance issues
Michael Bayer wrote: also, I challenge your assertion that saying x and y or z is a perlish thing (its a C and Java thing if anything); python 2.5 has just added the y if x else z syntax which is essentially an official version of the same thing. Well, I wasn't really talking about 'x and y or z'. I was actually referring to your HUGE incomprehensible one-liner...it wrapped to three lines in my editor. However, the 'x and y or z' idiom is also discouraged because it is NOT the same thing as 'y if x else z'. If it was the same thing then they wouldn't have added that new syntax (which is really ugly IMO, but I digress) to 2.5. The reason they needed a new syntax is because the 'x and y or z' idiom fails if y evaluates to false. Example: x = True y = '' z = 'else' v = x and y or z assert v == y # ERROR! ~ Daniel --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: SA 0.3.x: performance issues
it is flawed for that reason yes. fine for non-empty strings though. the new syntax is meant to do correctly what we *want* the x and y or z thing to do. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---