sqlalchemy-tickets Mailing List for SQLAlchemy (Page 41)
Brought to you by:
zzzeek
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(174) |
Apr
(50) |
May
(71) |
Jun
(129) |
Jul
(113) |
Aug
(141) |
Sep
(82) |
Oct
(142) |
Nov
(97) |
Dec
(72) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(159) |
Feb
(213) |
Mar
(156) |
Apr
(151) |
May
(58) |
Jun
(166) |
Jul
(296) |
Aug
(198) |
Sep
(89) |
Oct
(133) |
Nov
(150) |
Dec
(122) |
| 2008 |
Jan
(144) |
Feb
(65) |
Mar
(71) |
Apr
(69) |
May
(143) |
Jun
(111) |
Jul
(113) |
Aug
(159) |
Sep
(81) |
Oct
(135) |
Nov
(107) |
Dec
(200) |
| 2009 |
Jan
(168) |
Feb
(109) |
Mar
(141) |
Apr
(128) |
May
(119) |
Jun
(132) |
Jul
(136) |
Aug
(154) |
Sep
(151) |
Oct
(181) |
Nov
(223) |
Dec
(169) |
| 2010 |
Jan
(103) |
Feb
(209) |
Mar
(201) |
Apr
(183) |
May
(134) |
Jun
(113) |
Jul
(110) |
Aug
(159) |
Sep
(138) |
Oct
(96) |
Nov
(116) |
Dec
(94) |
| 2011 |
Jan
(97) |
Feb
(188) |
Mar
(157) |
Apr
(158) |
May
(118) |
Jun
(102) |
Jul
(137) |
Aug
(113) |
Sep
(104) |
Oct
(108) |
Nov
(91) |
Dec
(162) |
| 2012 |
Jan
(189) |
Feb
(136) |
Mar
(153) |
Apr
(142) |
May
(90) |
Jun
(141) |
Jul
(67) |
Aug
(77) |
Sep
(113) |
Oct
(68) |
Nov
(101) |
Dec
(122) |
| 2013 |
Jan
(60) |
Feb
(77) |
Mar
(77) |
Apr
(129) |
May
(189) |
Jun
(155) |
Jul
(106) |
Aug
(123) |
Sep
(53) |
Oct
(142) |
Nov
(78) |
Dec
(102) |
| 2014 |
Jan
(143) |
Feb
(93) |
Mar
(35) |
Apr
(26) |
May
(27) |
Jun
(41) |
Jul
(45) |
Aug
(27) |
Sep
(37) |
Oct
(24) |
Nov
(22) |
Dec
(20) |
| 2015 |
Jan
(17) |
Feb
(15) |
Mar
(34) |
Apr
(55) |
May
(33) |
Jun
(31) |
Jul
(27) |
Aug
(17) |
Sep
(22) |
Oct
(26) |
Nov
(27) |
Dec
(22) |
| 2016 |
Jan
(20) |
Feb
(24) |
Mar
(23) |
Apr
(13) |
May
(17) |
Jun
(14) |
Jul
(31) |
Aug
(23) |
Sep
(24) |
Oct
(31) |
Nov
(23) |
Dec
(16) |
| 2017 |
Jan
(24) |
Feb
(20) |
Mar
(27) |
Apr
(24) |
May
(28) |
Jun
(18) |
Jul
(18) |
Aug
(23) |
Sep
(30) |
Oct
(17) |
Nov
(12) |
Dec
(12) |
| 2018 |
Jan
(27) |
Feb
(23) |
Mar
(13) |
Apr
(19) |
May
(21) |
Jun
(29) |
Jul
(11) |
Aug
(22) |
Sep
(14) |
Oct
(9) |
Nov
(24) |
Dec
|
|
From: Pieter M. <iss...@bi...> - 2015-03-18 15:20:09
|
New issue 3331: sqlalchemy 1.0.0b1 does not allow getting an declared_attr from declarative object https://bitbucket.org/zzzeek/sqlalchemy/issue/3331/sqlalchemy-100b1-does-not-allow-getting-an Pieter Mulder: The following code works without any problems in sqlalchemy 0.9.9 but fails in 1.0.0b1: ``` #!python import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declared_attr Base = declarative_base() class Abstract1(object): @declared_attr def __tablename__(cls): return cls.__name__.lower() class Concrete1(Abstract1, Base): id = sa.Column(sa.Integer, primary_key=True) Abstract1.__tablename__ Concrete1.__tablename__ ``` The exception: ``` #! <ipython-input-8-1445e04c4c3b> in <module>() ----> 1 Concrete1.__tablename__ /home/pieter/.virtualenvs/proigia_encryption/lib/python2.7/site-packages/sqlalchemy/ext/declarative/api.pyc in __get__(desc, self, cls) 180 except KeyError: 181 raise exc.InvalidRequestError( --> 182 "@declared_attr called outside of the " 183 "declarative mapping process; is declarative_base() being " 184 "used correctly?") InvalidRequestError: @declared_attr called outside of the declarative mapping process; is declarative_base() being used correctly? ``` |
|
From: Mike B. <iss...@bi...> - 2015-03-17 03:41:48
|
New issue 3330: fetchone() and others should not raise on a result that had rows https://bitbucket.org/zzzeek/sqlalchemy/issue/3330/fetchone-and-others-should-not-raise-on-a Mike Bayer: the resultproxy does an "autoclose", but fetchone() and others should continue to return None or empty list, the same way pep 249 states. ``` #!python >>> from sqlalchemy import create_engine >>> e = create_engine("sqlite://") >>> r = e.execute("select 1") >>> r.fetchone() (1,) >>> r.fetchone() >>> r.fetchone() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py", line 930, in fetchone self.cursor, self.context) File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1335, in _handle_dbapi_exception util.reraise(*exc_info) File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py", line 921, in fetchone row = self._fetchone_impl() File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py", line 840, in _fetchone_impl self._non_result() File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/engine/result.py", line 864, in _non_result raise exc.ResourceClosedError("This result object is closed.") sqlalchemy.exc.ResourceClosedError: This result object is closed. >>> ``` |
|
From: Mike B. <iss...@bi...> - 2015-03-17 03:36:52
|
New issue 3329: fetchmany() fails on bufferedcolproxy on second call w/ no rows https://bitbucket.org/zzzeek/sqlalchemy/issue/3329/fetchmany-fails-on-bufferedcolproxy-on Mike Bayer: ``` #!diff diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 730ef44..a5318c0 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1070,6 +1070,9 @@ class AlternateResultProxyTest(fixtures.TestBase): rows = r.fetchmany(6) eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) + rows = r.fetchmany(2) + eq_(rows, []) + def test_plain(self): self._test_proxy(_result.ResultProxy) ``` |
|
From: David L. <iss...@bi...> - 2015-03-16 17:38:47
|
New issue 3328: `as_declarative` has moved https://bitbucket.org/zzzeek/sqlalchemy/issue/3328/as_declarative-has-moved David Lord: `as_declarative` has been removed from the top level module between 0.9.8 and 0.9.9. This no longer works: from sqlalchemy.ext.declarative import as_declarative Instead, this is required: from sqlalchemy.ext.declarative.api import as_declarative This seems to be an unintended change, as there's no reason for it to have been removed, and there's no mention in the changelog. Discovered while answering [this Stack Overflow question](http://stackoverflow.com/a/29083190/400617). |
|
From: Mike B. <iss...@bi...> - 2015-03-16 15:14:32
|
New issue 3327: py2k unicodes not accepted by cascade https://bitbucket.org/zzzeek/sqlalchemy/issue/3327/py2k-unicodes-not-accepted-by-cascade Mike Bayer: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) bs = relationship("B", cascade=u"all, delete-orphan") class B(Base): __tablename__ = 'b' id = Column(Integer, primary_key=True) a_id = Column(ForeignKey('a.id')) ``` due to hardcoded "str" in orm/util |
|
From: Leonardo R. <iss...@bi...> - 2015-03-16 09:24:14
|
New issue 3326: Grant user privileges https://bitbucket.org/zzzeek/sqlalchemy/issue/3326/grant-user-privileges Leonardo Rossi: Exists the possibility to use SQLAlchemy to create user and grant privilege on the DB? |
|
From: Curtis F. <iss...@bi...> - 2015-03-15 13:31:07
|
New issue 3325: Simple typo in "Inserts, Updates and Deletes" section https://bitbucket.org/zzzeek/sqlalchemy/issue/3325/simple-typo-in-inserts-updates-and-deletes Curtis Forrester: In text: "Where insert() prodces INSERT..." should be "produces" [http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#inserts-updates-and-deletes](http://docs.sqlalchemy.org/en/rel_0_9/core/tutorial.html#inserts-updates-and-deletes). |
|
From: Eben F. <iss...@bi...> - 2015-03-12 19:21:45
|
New issue 3324: `from sqlalchemy.ext.declarative import as_declarative` fails in 0.9.9 https://bitbucket.org/zzzeek/sqlalchemy/issue/3324/from-sqlalchemyextdeclarative-import Eben Freeman: Hi, Looks like `sqlalchemy.ext.declarative.__init__.py` no longer imports `as_declarative` in 0.9.9. Not a major problem for us, but seems likely to be a typo in the release, rather than an intentional change? |
|
From: Guido W. <iss...@bi...> - 2015-03-12 17:08:34
|
New issue 3323: In 0.9.9, uuid columns are broken with postgresql+psycopg2 https://bitbucket.org/zzzeek/sqlalchemy/issue/3323/in-099-uuid-columns-are-broken-with Guido Winkelmann: Starting with release 0.9.9, inserting a model with a primary key column of type uuid.uuid4, when running against postgresql with psycopg2, will raise this exception: `StatementError: 'UUID' object has no attribute 'replace' (original cause: AttributeError: 'UUID' object has no attribute 'replace')` For a real life example, see here: https://travis-ci.org/pyfarm/pyfarm-master/jobs/53941909 This only happens with postgresql as a backend. MySQL and SQLite are not affected. Unfortunately, I haven't found time to produce a reduced test case yet. |
|
From: Eduardo D. <iss...@bi...> - 2015-03-12 15:41:58
|
New issue 3322: SafeNumeric TypeDecorator recipe on documentation: wrong semantics https://bitbucket.org/zzzeek/sqlalchemy/issue/3322/safenumeric-typedecorator-recipe-on Eduardo Dobay: When rounding a Decimal to fit in a database column, the number of digits that must remain following the decimal point should be the **scale** — please correct me if I am interpreting this incorrectly; I'm using the terminology from MySQL docs. According to this understanding, in the SafeNumeric TypeDecorator recipe in the Custom Types section of the documentation, the values are being rounded using `precision - scale` digits, which is actually the number of digits *before* the decimal point. So that should be replaced by just `scale`. |
|
From: Mike B. <iss...@bi...> - 2015-03-11 20:43:16
|
New issue 3321: consider locking down _literal_as_binds() and similar to correct for common errors, e.g. mapped classes passed in https://bitbucket.org/zzzeek/sqlalchemy/issue/3321/consider-locking-down-_literal_as_binds Mike Bayer: |
|
From: Hugo B. <iss...@bi...> - 2015-03-11 13:09:48
|
New issue 3320: Query.with_entities don't "copy" query options https://bitbucket.org/zzzeek/sqlalchemy/issue/3320/querywith_entities-dont-copy-query-options Hugo Braquinho: I'm doing some pagination and trying to count the number of results ``` #!python query = session.query(Group.id) print query # SELECT groups.id AS groups_id FROM groups print query.with_entities(func.count(1)) # SELECT count(:param_1) AS count_1 ``` The count query don't have any FROM, i understand why this happen, but there is no way to preserve query froms? I can fix this adding all entities ``` #!python query = session.query(Group.id) print query # SELECT groups.id AS groups_id FROM groups print query.with_entities(func.count(1), *[e.expr for e in query._entities]) # SELECT count(:param_1) AS count_1, iduc_groups.id AS iduc_groups_id FROM iduc_groups ``` But i don't know if it works for every defined entities |
|
From: Leonardo R. <iss...@bi...> - 2015-03-11 12:34:30
|
New issue 3319: PostgreSQL Enum not automatically dropped https://bitbucket.org/zzzeek/sqlalchemy/issue/3319/postgresql-enum-not-automatically-dropped Leonardo Rossi: I have some problem when I try to drop al the tables in the db. https://github.com/hachreak/invenio/blob/master/invenio/base/scripts/database.py#L165 When it's invoked, all the tables are correctly dropped, but the Enum (Type in PostgreSQL) are not dropped. Do you have some ideas how can I resolve this problem? :) |
|
From: __tosh <iss...@bi...> - 2015-03-11 12:05:02
|
New issue 3318: dictinct(Model) generates unexpected query https://bitbucket.org/zzzeek/sqlalchemy/issue/3318/dictinct-model-generates-unexpected-query __tosh: Hi there, I use SQLAlchemy 0.8.3 (so maybe it's fixed in newer releases) with MySQL 5.1.73. When I do the query ``` #!python Session.query(distinct(Model)) ``` it generates something like ``` #!SQL SELECT DISTINCT :param_1 AS anon_1; ``` Where :param_1 is replaced with Model.\_\_repr\_\_() which is a simple string. Maybe it would be more obvious if such SQLAlchemy-queries generated the following code? ``` #!SQL SELECT DISTINCT * AS anon_1 FROM model_table; ``` |
|
From: Mike B. <iss...@bi...> - 2015-03-10 23:06:36
|
New issue 3317: create query before_compile event https://bitbucket.org/zzzeek/sqlalchemy/issue/3317/create-query-before_compile-event Mike Bayer: part of #3225 |
|
From: Ander U. <iss...@bi...> - 2015-03-06 14:47:46
|
New issue 3316: Default value doesn't work in SQLAlchemy + PostgreSQL https://bitbucket.org/zzzeek/sqlalchemy/issue/3316/default-value-doesnt-work-in-sqlalchemy Ander Ustarroz: I've found an unexpected behavior in SQLAlchemy. I'm using the following versions: * SQLAlchemy (0.9.8) * psycopg2 (2.5.4) * PostgreSQL (9.3.5) This is the table definition for the example: ``` #!python from sqlalchemy import ( MetaData, Column, Integer, Table, String, ) metadata = Metadata() users = Table('users', metadata, Column('id_user', Integer, primary_key=True, nullable=False), Column('name', String(20), unique=True), Column('age', Integer, nullable=False, default=0), ) ``` If now I try to execute a simple insert to the table just populating the **id_user** and **name**, the column **age** should be auto-generated right? Lets see... ``` #!python data = {'id_user':1, 'name':'Jimmy' } stmt = users.insert().values(data) ``` This is the resulting statement: ``` #!sql INSERT INTO users (id_user, name, age) VALUES (1, 'Jimmy', null); ``` But the **age** column was not provided, where is that null coming from? I was expecting this: ``` #!sql INSERT INTO users (id_user, name) VALUES (1, 'Jimmy'); ``` Or if the ***default*** flag actually works should be: ``` #!sql INSERT INTO users (id_user, name, Age) VALUES (1, 'Jimmy', 0); ``` Could you put some light on this? |
|
From: Andrea G. <iss...@bi...> - 2015-03-04 14:46:42
|
New issue 3315: MySQL Connector >= 2.0.0, Python 3.4 always returns bytearrays instead of (unicode) strings https://bitbucket.org/zzzeek/sqlalchemy/issue/3315/mysql-connector-200-python-34-always Andrea Gronchi: I'm using SQLAlchemy 9.8.0 and MySQL Connector 2.0.3. I've found myself unable to get unicode data (intending the PY3 type "str"), every text field was always obtained as byte array data. Passing explicitly convert_unicode=True had no effect; declaring columns as UnicodeText had no effect; coercing connection options "use_unicode=1&charset=…" had no effect. I have gave out and moved on to PyMySql; everything worked instantly. Then I found this release note http://dev.mysql.com/doc/relnotes/connector-python/en/news-2-0-0.html , which basically notifies about the braking change of always returning bytearray data while using raw cursors. I don't know if this might be the case but it's probably worth looking into. |
|
From: Viktor R. <iss...@bi...> - 2015-02-27 22:58:44
|
New issue 3314: Return a namedtuple for inserted_primary_key https://bitbucket.org/zzzeek/sqlalchemy/issue/3314/return-a-namedtuple-for Viktor Roytman: Hello, It's a bit annoying that the inserted_primary_key is a list instead of something with some useful metadata. If it were a namedtuple instead, a user could access the keys by name in addition to the existing method (by index). The documentation for namedtuple even recommends usage like this: *Named tuples are especially useful for assigning field names to result tuples returned by the csv or sqlite3 modules* For what it's worth, psycopg2 allows for namedtuple cursors: [http://initd.org/psycopg/docs/extras.html#namedtuple-cursor](http://initd.org/psycopg/docs/extras.html#namedtuple-cursor) (from [https://docs.python.org/3/library/collections.html#collections.namedtuple](https://docs.python.org/3/library/collections.html#collections.namedtuple)) |
|
From: Michał K. <iss...@bi...> - 2015-02-27 13:28:54
|
New issue 3313: Identyfier to long in Oracle https://bitbucket.org/zzzeek/sqlalchemy/issue/3313/identyfier-to-long-in-oracle Michał Kaczmarek: Hi, I've got a problem with oracle tables. Identifier is too long, because my tables have long names and column names are also long so when identyfier is created it's more than 30 characters long. Is any posibility to work with that without changing table and column names? Maybe by add param label() on Column()? Best regards Michał |
|
From: nyov <iss...@bi...> - 2015-02-25 15:57:43
|
New issue 3312: select() parameter to avoid "Ambiguous column name" for a simple join on? https://bitbucket.org/zzzeek/sqlalchemy/issue/3312/select-parameter-to-avoid-ambiguous-column nyov: Would it be possible to have a parameter to `sqlalchemy.sql.expression.select()` to avoid the "Ambiguous column name" exception for simple joins? I don't care for the `use_labels` here as I then have to rewrite all the keys again after. If possible, I'd like a parameter to select that would then simply drop the column name on the right side of the join (where the value is the same for such a join) from the select column list. As in "select all but joined_on_column duplicate". This'd be a nicer, quicker way than writing out all the many column names manually or working with an alias for a column I still don't need as it's just a duplicate. |
|
From: Dani H. <iss...@bi...> - 2015-02-21 18:33:51
|
New issue 3311: Howto: Difficult self referencing queries https://bitbucket.org/zzzeek/sqlalchemy/issue/3311/howto-difficult-self-referencing-queries Dani Hodovic: I'm wondering how the following two queries could be elegantly composed in SqlAlchemy. SELECT t1.* FROM mytable t1 LEFT OUTER JOIN mytable t2 ON (t1.UserId = t2.UserId AND t1."Date" < t2."Date") WHERE t2.UserId IS NULL; and select userid, value from users u1 where date = (select max(date) from users u2 where u1.userid = u2.userid) The queries can be found here: http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column/121435#121435 I think I've figured out query 1, but I'm not sure if my solution is optimal (can post if needed, don't want to make a wall of text). In general how do you self reference a table in a subquery as in example 2? Thanks |
|
From: Brandon C. <iss...@bi...> - 2015-02-20 18:47:13
|
New issue 3310: Relationship __ne__ does not handle aliased() properly https://bitbucket.org/zzzeek/sqlalchemy/issue/3310/relationship-__ne__-does-not-handle Brandon Clarke: Found from SO post [Here](https://stackoverflow.com/questions/28610563/sqlalchemy-different-output-on-queries-field-is-null-and-is-not-null-on-ali). Sample code to reproduce: from sqlalchemy import * from sqlalchemy.orm import aliased from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relation, sessionmaker, relationship, backref Base = declarative_base() class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) children = relation('Child', back_populates='parents') class Child(Base): __tablename__ = 'child' id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey('parent.id')) parents = relation('Parent', back_populates='children', uselist=False) aChild = aliased(Child) Session = sessionmaker() Session = Session() print Session.query(aChild.id).filter(~(aChild.parents == None)) """ SELECT children_1.id AS children_1_id FROM children AS children_1 WHERE children_1.parent_id IS NOT NULL """ print Session.query(aChild.id).filter(aChild.parents != None) #failing case """ SELECT children_1.id AS children_1_id FROM children AS children_1, children WHERE children.parent_id IS NOT NULL """ I did some poking around and have a proposed fix, below: @@ -1291,8 +1291,8 @@ class RelationshipProperty(StrategizedProperty): """ if isinstance(other, (util.NoneType, expression.Null)): if self.property.direction == MANYTOONE: - return sql.or_(*[x != None for x in - self.property._calculated_foreign_keys]) + return _orm_annotate(~self.property._optimized_compare( + None, adapt_source=self.adapter)) I basically used the logic in place for __eq__ and inverted it. It passes all existing test cases, I'm just working on creating a test case for this failure mode. I was planning on wrapping up a pull request today. If there are any suggestions for where to locate the test, please let me know. First time submitting anything here, so if I'm doing anything wrong, please let me know that too |
|
From: zoomorph <iss...@bi...> - 2015-02-19 06:09:48
|
New issue 3309: AssertionError in rollback on failed commit. https://bitbucket.org/zzzeek/sqlalchemy/issue/3309/assertionerror-in-rollback-on-failed zoomorph: My commit code... ``` try: self._session.commit() except Exception as e: logger.exception("Caught exception in commit.") self.rollback() ``` Caught the following exception: ``` Traceback (most recent call last): File "/myapp/tpcommon/db/core.py", line 111, in commit self._session.commit() File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 779, in commit self.transaction.commit() File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 384, in commit self._prepare_impl() File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 364, in _prepare_impl self.session.flush() File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 1993, in flush self._flush(objects) File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 2111, in _flush transaction.rollback(_capture_exception=True) File "/myapp/env_pypy/site-packages/sqlalchemy/util/langhelpers.py", line 63, in __exit__ compat.reraise(type_, value, traceback) File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 2111, in _flush transaction.rollback(_capture_exception=True) File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 426, in rollback self._restore_snapshot(dirty_only=self.nested) File "/myapp/env_pypy/site-packages/sqlalchemy/orm/session.py", line 266, in _restore_snapshot assert self._is_transaction_boundary AssertionError ``` When the exception handler called rollback(), it again raised this exception. After that, my code received the following when trying to continue using the session: ```InvalidRequestError: This Session's transaction has been rolled back by a nested rollback() call. To begin a new transaction, issue Session.rollback() first. ``` I'm using master branch code from about a week ago. I'm not sure what causes this error but it's happening infrequently. |
|
From: thiefmaster <iss...@bi...> - 2015-02-18 13:06:37
|
New issue 3308: Cannot use hybrid_property in filter_by https://bitbucket.org/zzzeek/sqlalchemy/issue/3308/cannot-use-hybrid_property-in-filter_by thiefmaster: ```python from sqlalchemy import * from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True) foo = Column(Integer) @hybrid_property def foo_123(self): return self.foo == 123 e = create_engine('postgresql:///test', echo=True) Base.metadata.create_all(e) s = Session(e) s.query(Test).filter_by(foo_123=True).all() ``` The WHERE clause generated from this is `test.foo = 123 = true` which fails. I think it should be `WHERE (test.foo = 123) = true ` instead. Maybe a hybrid property could automatically insert parentheses around the generated criterion? That shouldn't break anything but avoid this bug. |
|
From: zoomorph <iss...@bi...> - 2015-02-13 10:20:54
|
New issue 3307: Performance with PyPy https://bitbucket.org/zzzeek/sqlalchemy/issue/3307/performance-with-pypy zoomorph: SQLAlchemy seems to run quite a bit slower (2-3x) under PyPy. I've gathered some pstats profiles comparing the two. PyPy (latest nightly build) + SQLAlchemy (master branch) + psycopg2cffi: ``` #!python 1 0.000 0.000 0.017 0.017 /myapp/tpserv/client/client.py:285(handle_client_line) 1 0.000 0.000 0.017 0.017 /myapp/tpserv/client/client.py:859(handle_request_statistics) 1 0.000 0.000 0.017 0.017 /myapp/tpserv/tank/tank.py:419(initial_load) 1 0.000 0.000 0.014 0.014 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:2435(first) 1 0.000 0.000 0.014 0.014 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:2267(__getitem__) 1 0.000 0.000 0.012 0.012 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:2516(__iter__) 1 0.000 0.000 0.010 0.010 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:2530(_execute_and_instances) 1 0.000 0.000 0.010 0.010 /myapp/env_pypy/site-packages/sqlalchemy/engine/base.py:846(execute) 1 0.000 0.000 0.010 0.010 /myapp/env_pypy/site-packages/sqlalchemy/sql/elements.py:322(_execute_on_connection) 1 0.000 0.000 0.010 0.010 /myapp/env_pypy/site-packages/sqlalchemy/engine/base.py:975(_execute_clauseelement) 1 0.000 0.000 0.005 0.005 <string>:1(<lambda>) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/elements.py:431(compile) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/elements.py:496(_compiler) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:328(__init__) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:166(__init__) 2/1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:211(process) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/engine/base.py:1062(_execute_context) 50/1 0.002 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/visitors.py:75(_compiler_dispatch) 1 0.000 0.000 0.005 0.005 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:1474(visit_select) 22 0.000 0.000 0.003 0.000 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:1254(_label_select_column) 1 0.000 0.000 0.003 0.003 /myapp/env_pypy/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py:457(get_result_proxy) 1 0.000 0.000 0.003 0.003 /myapp/env_pypy/site-packages/sqlalchemy/engine/result.py:407(__init__) 1 0.000 0.000 0.003 0.003 /myapp/env_pypy/site-packages/sqlalchemy/engine/result.py:423(_init_metadata) 1 0.003 0.003 0.003 0.003 /myapp/env_pypy/site-packages/sqlalchemy/engine/result.py:189(__init__) 22 0.000 0.000 0.003 0.000 /myapp/env_pypy/site-packages/sqlalchemy/sql/compiler.py:551(visit_label) 2 0.000 0.000 0.002 0.001 /myapp/env_pypy/site-packages/sqlalchemy/orm/loading.py:27(instances) 2 0.000 0.000 0.002 0.001 /myapp/env_pypy/site-packages/psycopg2cffi/_impl/cursor.py:18(check_closed_) 1 0.000 0.000 0.002 0.002 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:2934(_compile_context) 2 0.000 0.000 0.001 0.001 /usr/local/pypy/lib-python/2.7/logging/__init__.py:1163(info) 2 0.000 0.000 0.001 0.001 /usr/local/pypy/lib-python/2.7/logging/__init__.py:1273(_log) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/engine/default.py:441(do_execute) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/psycopg2cffi/_impl/cursor.py:193(execute) 10/5 0.000 0.000 0.001 0.000 /myapp/env_pypy/site-packages/sqlalchemy/sql/operators.py:294(__eq__) 2 0.000 0.000 0.001 0.001 /usr/local/pypy/lib-python/2.7/logging/__init__.py:1294(handle) 9/7 0.000 0.000 0.001 0.000 {operator.eq} 2 0.000 0.000 0.001 0.001 /usr/local/pypy/lib-python/2.7/logging/__init__.py:1326(callHandlers) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:3297(setup_context) 6 0.000 0.000 0.001 0.000 /usr/local/pypy/lib-python/2.7/logging/__init__.py:757(handle) 3 0.000 0.000 0.001 0.000 /myapp/env_pypy/site-packages/sqlalchemy/orm/attributes.py:174(operate) 48 0.001 0.000 0.001 0.000 /myapp/env_pypy/site-packages/sqlalchemy/orm/interfaces.py:459(_get_context_loader) 1 0.001 0.001 0.001 0.001 /myapp/env_pypy/site-packages/psycopg2cffi/_impl/cursor.py:675(_pq_execute) 24 0.000 0.000 0.001 0.000 /myapp/env_pypy/site-packages/sqlalchemy/orm/interfaces.py:491(setup) 2 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/orm/relationships.py:950(__eq__) 6 0.000 0.000 0.001 0.000 /usr/local/pypy/lib-python/2.7/logging/__init__.py:860(emit) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/orm/query.py:3258(row_processor) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/orm/loading.py:221(instance_processor) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/engine/result.py:806(fetchall) 1 0.000 0.000 0.001 0.001 /myapp/env_pypy/site-packages/sqlalchemy/engine/result.py:775(_fetchall_impl) ``` Python 2.7 + SQLAlchemy (master branch) + psycopg2: ``` #!python 1 0.000 0.000 0.005 0.005 /myapp/tpserv/client/client.py:285(handle_client_line) 1 0.000 0.000 0.005 0.005 /myapp/tpserv/client/client.py:859(handle_request_statistics) 1 0.000 0.000 0.005 0.005 /myapp/tpserv/tank/tank.py:419(initial_load) 1 0.000 0.000 0.004 0.004 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py:2435(first) 1 0.000 0.000 0.004 0.004 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py:2267(__getitem__) 1 0.000 0.000 0.003 0.003 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py:2516(__iter__) 1 0.000 0.000 0.003 0.003 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py:2530(_execute_and_instances) 1 0.000 0.000 0.003 0.003 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py:846(execute) 1 0.000 0.000 0.003 0.003 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:322(_execute_on_connection) 1 0.000 0.000 0.003 0.003 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py:975(_execute_clauseelement) 1 0.000 0.000 0.001 0.001 <string>:1(<lambda>) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:431(compile) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:496(_compiler) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:328(__init__) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:166(__init__) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py:1062(_execute_context) 2/1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:211(process) 50/1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py:75(_compiler_dispatch) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:1474(visit_select) 2 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:1142(info) 2 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:1252(_log) 2 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:1273(handle) 2 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:1305(callHandlers) 6 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:736(handle) 22 0.000 0.000 0.001 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:1254(_label_select_column) 1 0.000 0.000 0.001 0.001 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py:441(do_execute) 1 0.001 0.001 0.001 0.001 {method 'execute' of 'psycopg2._psycopg.cursor' objects} 6 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:839(emit) 22 0.000 0.000 0.001 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:551(visit_label) 4 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/handlers.py:68(emit) 10/5 0.000 0.000 0.001 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/operators.py:294(__eq__) 4 0.000 0.000 0.001 0.000 /usr/lib/python2.7/logging/__init__.py:933(emit) 9/7 0.000 0.000 0.001 0.000 {operator.eq} 1 0.000 0.000 0.001 0.001 /usr/lib/python2.7/contextlib.py:21(__exit__) 1 0.000 0.000 0.001 0.001 /myapp/tpcommon/profile.py:11(profile) 3 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py:174(operate) 2 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py:950(__eq__) 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py:2934(_compile_context) 2 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/orm/loading.py:27(instances) 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:1616(_compose_select_body) 26 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:590(visit_column) 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py:457(get_result_proxy) 8/2 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py:86(_compiler_dispatch) 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/result.py:407(__init__) 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/result.py:423(_init_metadata) 7/6 0.000 0.000 0.000 0.000 {method 'join' of 'str' objects} 1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py:507(_init_compiled) 2/1 0.000 0.000 0.000 0.000 /myapp/env_python/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py:705(visit_clauselist) ``` initial_load basically executes one select query. Perhaps some optimizations can be made for better PyPy performance? |