89 Commits

Author SHA1 Message Date
Mike Bayer 18abd47af3 Post black reformatting
Applied on top of a pure run of black -l 79 in
I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9,  this set of changes
resolves all remaining flake8 conditions for those codes
we have enabled in setup.cfg.

Included are resolutions for all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
2019-01-06 11:51:20 -05:00
Mike Bayer 580139598f Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits
applied at all.

The black run will format code consistently, however in
some cases that are prevalent in SQLAlchemy code it produces
too-long lines.   The too-long lines will be resolved in the
following commit that will resolve all remaining flake8 issues
including shadowed builtins, long lines, import order, unused
imports, duplicate imports, and docstring issues.

Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
2019-01-06 01:31:01 -05:00
Lele Gaifax 7ec092063a commit 1b774808c926665047bf353222ecd191679a95d1
Author: Lele Gaifax <lele@metapensiero.it>
Date:   Tue Dec 25 12:35:41 2018 +0100

    Consistently use "PostgreSQL", fixing also a few doc glitches

commit 0e382aaee4427193926f0dc10ad29056bc12c85e
Author: Lele Gaifax <lele@metapensiero.it>
Date:   Tue Dec 25 12:08:49 2018 +0100

    Remove duplicated words

Change-Id: Iaa586b9412f46a50fe6ff3bbb92e07d6cb1905c8
(cherry picked from commit c0f9708fde)
2018-12-30 21:20:20 -05:00
Mike Bayer 7bb4923391 Use consistent method signature for Alias.self_group()
Fixed bug where the use of an :class:`.Alias` object in a column
context would raise an argument error when it tried to group itself
into a parenthesized expression.   Using :class:`.Alias` in this way
is not yet a fully supported API, however it applies to some end-user
recipes and may have a more prominent role in support of some
future Postgresql features.

Change-Id: I81717e30416e0350f08d1e022c3d84656e0a9735
Fixes: #3939
2017-04-03 12:14:33 -04:00
Khairi Hafsham 772374735d Make all tests to be PEP8 compliant
tested using pycodestyle version 2.2.0

Fixes: #3885
Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
2017-02-07 11:21:56 -05:00
Mike Bayer 25804aeae2 Repair foreign_keys population for Join._refresh_for_new_column
Fixed bug where setting up a single-table inh subclass of a joined-table
subclass which included an extra column would corrupt the foreign keys
collection of the mapped table, thereby interfering with the
initialization of relationships.

Change-Id: I04a0cf98fd456d12d5a5b9e77a46a01246969a63
Fixes: #3797
2016-09-15 00:54:15 -04:00
Mike Bayer 07a4b6cbcd - Fixed bug where the negation of an EXISTS expression would not
be properly typed as boolean in the result, and also would fail to be
anonymously aliased in a SELECT list as is the case with a
non-negated EXISTS construct.
fixes #3682
2016-03-21 10:57:40 -04:00
Mike Bayer 39837686b0 - calling str() on a core sql construct has been made more "friendly",
when the construct contains non-standard sql elements such as
returning, array index operations, or dialect-specific or custom
datatypes.  a string is now returned in these cases rendering an
approximation of the construct (typically the postgresql-style
version of it) rather than raising an error. fixes #3631
- add within_group to top-level imports
- add eq_ignore_whitespace to sqlalchemy.testing imports
2016-01-19 16:47:16 -05:00
Mike Bayer 7c4512cbeb - Added support for "set-aggregate" functions of the form
``<function> WITHIN GROUP (ORDER BY <criteria>)``, using the
method :class:`.FunctionElement.within_group`.  A series of common
set-aggregate functions with return types derived from the set have
been added. This includes functions like :class:`.percentile_cont`,
:class:`.dense_rank` and others.
fixes #1370
- make sure we use func.name for all _literal_as_binds in functions.py
so we get consistent naming behavior for parameters.
2015-08-26 17:19:27 -04:00
Mike Bayer 88749550f6 - The behavior of the :func:.union construct and related constructs
such as :meth:`.Query.union` now handle the case where the embedded
SELECT statements need to be parenthesized due to the fact that they
include LIMIT, OFFSET and/or ORDER BY.   These queries **do not work
on SQLite**, and will fail on that backend as they did before, but
should now work on all other backends.
fixes #2528
2015-08-12 14:26:11 -04:00
Mike Bayer 3e80d628bd - Fixed issue where a straight SELECT EXISTS query would fail to
assign the proper result type of Boolean to the result mapping, and
instead would leak column types from within the query into the
result map.  This issue exists in 0.9 and earlier as well, however
has less of an impact in those versions.  In 1.0, due to #918
this becomes a regression in that we now rely upon the result mapping
to be very accurate, else we can assign result-type processors to
the wrong column.   In all versions, this issue also has the effect
that a simple EXISTS will not apply the Boolean type handler, leading
to simple 1/0 values for backends without native boolean instead of
True/False.   The fix includes that an EXISTS columns argument
will be anon-labeled like other column expressions; a similar fix is
implemented for pure-boolean expressions like ``not_(True())``.
fixes #3372
2015-04-20 19:21:00 -04:00
Mike Bayer 9854114f57 foo 2015-03-08 11:34:14 -04:00
Mike Bayer 81d1e0455a - Fixed bug where a fair number of SQL elements within
the sql package would fail to ``__repr__()`` successfully,
due to a missing ``description`` attribute that would then invoke
a recursion overflow when an internal AttributeError would then
re-invoke ``__repr__()``.
fixes #3195
2014-10-09 17:20:30 -04:00
Mike Bayer c52580dede - rework ColumnAdapter and ORMAdapter to only provide the features
we're now using; rework them fully so that their behavioral contract
is consistent regarding adapter.traverse() vs. adapter.columns[],
add a full suite of tests including advanced wrapping scenarios
previously only covered by test/orm/test_froms.py and
test/orm/inheritance/test_relationships.py
- identify several cases where label._order_by_label_clause would be
corrupted, e.g. due to adaption or annotation separately
- add full tests for #3148
2014-09-07 14:55:44 -04:00
Mike Bayer bb5f4392a4 - update the flake8 rules again
- apply autopep8 + manual fixes to most of test/sql/
2014-07-18 17:40:58 -04:00
Mike Bayer e6cbd88fe1 - Fixed bug in SQLite join rewriting where anonymized column names
due to repeats would not correctly be rewritten in subqueries.
This would affect SELECT queries with any kind of subquery + join.
fixes #3057
2014-05-25 11:32:07 -04:00
Alex Gaynor 1caa7fafbd Fix many typos throughout the codebase
Found using: https://github.com/intgr/topy
2014-04-26 13:13:13 -07:00
Mike Bayer 9c731b2ebf - add further coverage for join_condition to make sure we get this case where
there are multiple, equivalent foreign keys
2014-03-28 16:41:08 -04:00
Mike Bayer 302ad6228a - Some changes to how the :attr:.FromClause.c collection behaves
when presented with duplicate columns.  The behavior of emitting a
warning and replacing the old column with the same name still
remains to some degree; the replacement in particular is to maintain
backwards compatibility.  However, the replaced column still remains
associated with the ``c`` collection now in a collection ``._all_columns``,
which is used by constructs such as aliases and unions, to deal with
the set of columns in ``c`` more towards what is actually in the
list of columns rather than the unique set of key names.  This helps
with situations where SELECT statements with same-named columns
are used in unions and such, so that the union can match the columns
up positionally and also there's some chance of :meth:`.FromClause.corresponding_column`
still being usable here (it can now return a column that is only
in selectable.c._all_columns and not otherwise named).
The new collection is underscored as we still need to decide where this
list might end up.   Theoretically it
would become the result of iter(selectable.c), however this would mean
that the length of the iteration would no longer match the length of
keys(), and that behavior needs to be checked out.
fixes #2974
- add a bunch more tests for ColumnCollection
2014-02-26 15:34:49 -05:00
Mike Bayer bf67069d26 - Fixed issue in new :meth:.TextClause.columns method where the ordering
of columns given positionally would not be preserved.   This could
have potential impact in positional situations such as applying the
resulting :class:`.TextAsFrom` object to a union.
2014-02-26 13:28:14 -05:00
Mike Bayer bf934018a5 - for TextAsFrom, put the "inner" columns in the result map directly.
Have also considered linking column.label() to the "column" itself being
in the result map but this reveals some naming collision problems (that
also seem to be very poorly tested...).   This should be as far as
we want to go right now with [ticket:2932].
2014-02-10 19:17:00 -05:00
Mike Bayer 15b23c7f71 - Fixed an 0.9 regression where the automatic aliasing applied by
:class:`.Query` and in other situations where selects or joins
were aliased (such as joined table inheritance) could fail if a
user-defined :class:`.Column` subclass were used in the expression.
In this case, the subclass would fail to propagate ORM-specific
"annotations" along needed by the adaptation.  The "expression
annotations" system has been corrected to account for this case.
[ticket:2918]
2014-01-23 14:49:04 -05:00
Mike Bayer 31cecebd48 - add support for specifying tables or entities for "of"
- implement Query with_for_update()
- rework docs and tests
2013-11-28 23:23:27 -05:00
Mike Bayer 4aaf3753d7 - fix up rendering of "of"
- move out tests, dialect specific out of compiler, compiler tests use new API,
legacy API tests in test_selecatble
- add support for adaptation of ForUpdateArg, alias support in compilers
2013-11-28 22:25:09 -05:00
Mike Bayer e74627f827 A :func:.select that is made to refer to itself in its FROM clause,
typically via in-place mutation, will raise an informative error
message rather than causing a recursion overflow.
[ticket:2815]
2013-10-08 20:06:58 -04:00
Mike Bayer 9df4651fba Fixed bug where using an annotation such as :func:.remote or
:func:`.foreign` on a :class:`.Column` before association with a parent
:class:`.Table` could produce issues related to the parent table not
rendering within joins, due to the inherent copy operation performed
by an annotation. [ticket:2813]
2013-10-08 19:47:13 -04:00
Mike Bayer 0ca7b53b42 Fixed bug where the expression system relied upon the `str()`
form of a some expressions when referring to the ``.c`` collection
on a ``select()`` construct, but the ``str()`` form isn't available
since the element relies on dialect-specific compilation constructs,
notably the ``__getitem__()`` operator as used with a Postgresql
``ARRAY`` element.  The fix also adds a new exception class
:class:`.UnsupportedCompilationError` which is raised in those cases
where a compiler is asked to compile something it doesn't know
how to.  Also in 0.8.3.
[ticket:2780]
2013-07-12 11:32:34 -04:00
Mike Bayer f76cae4bc9 - rework of correlation, continuing on #2668, #2746
- add support for correlations to propagate all the way in; because
correlations require context now, need to make sure a select enclosure
of any level takes effect any number of levels deep.
- fix what we said correlate_except() was supposed to do when we first
released #2668 - "the FROM clause is left intact if the correlated SELECT
is not used in the context of an enclosing SELECT..." - it was not
considering the "existing_froms" collection at all, and prohibited
additional FROMs from being placed in an any() or has().
- add test for multilevel any()
- lots of docs, including glossary entries as we really need to define
"WHERE clause", "columns clause" etc. so that we can explain correlation better
- based on the insight that a SELECT can correlate anything that ultimately
came from an enclosing SELECT that links to this one via WHERE/columns/HAVING/ORDER BY,
have the compiler keep track of the FROM lists that correspond in this way,
link it to the asfrom flag, so that we send to _get_display_froms() the exact
list of candidate FROMs to correlate.  no longer need any asfrom logic in the
Select() itself
- preserve 0.8.1's behavior for correlation when no correlate options are given, not
to mention 0.7 and prior's behavior of not propagating implicit correlation more than one level..
this is to reduce surprises/hard-to-debug situations when a user isn't trying
to correlate anything.
2013-06-26 13:19:45 -04:00
Mike Bayer e288aff8ea The resolution of :class:.ForeignKey objects to their
target :class:`.Column` has been reworked to be as
immediate as possible, based on the moment that the
target :class:`.Column` is associated with the same
:class:`.MetaData` as this :class:`.ForeignKey`, rather
than waiting for the first time a join is constructed,
or similar. This along with other improvements allows
earlier detection of some foreign key configuration
issues.  Also included here is a rework of the
type-propagation system, so that
it should be reliable now to set the type as ``None``
on any :class:`.Column` that refers to another via
:class:`.ForeignKey` - the type will be copied from the
target column as soon as that other column is associated,
and now works for composite foreign keys as well.
[ticket:1765]
2013-06-23 15:58:07 -04:00
Mike Bayer 31063d16f2 - tests for the alias() API
- docs docs docs
2013-06-08 18:41:59 -04:00
Mike Bayer 1188edccf6 fix test 2013-06-06 18:53:44 -04:00
Mike Bayer 26ec0507be Merge branch 'ticket_2587'
Conflicts:
	test/profiles.txt
	test/sql/test_selectable.py
2013-06-04 21:38:56 -04:00
Mike Bayer 66b8ed40c3 repair these tests now that we allow join from selectable to fromgrouping 2013-06-04 18:58:24 -04:00
Mike Bayer 8a865a4d1f Fixed bug whereby joining a select() of a table "A" with multiple
foreign key paths to a table "B", to that table "B", would fail
to produce the "ambiguous join condition" error that would be
reported if you join table "A" directly to "B"; it would instead
produce a join condition with multiple criteria.
[ticket:2738]
2013-06-03 17:03:15 -04:00
Mike Bayer 2ddcd20267 Merge branch 'master' into rel_0_9 2013-05-26 17:18:27 -04:00
Mike Bayer e2b8c893ca fix this test 2013-05-26 17:18:04 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer a5ede47f12 A major fix to the way in which a select() object produces
labeled columns when apply_labels() is used; this mode
produces a SELECT where each column is labeled as in
<tablename>_<columnname>, to remove column name collisions
for a multiple table select.   The fix is that if two labels
collide when combined with the table name, i.e.
"foo.bar_id" and "foo_bar.id", anonymous aliasing will be
applied to one of the dupes.  This allows the ORM to handle
both columns independently; previously, 0.7
would in some cases silently emit a second SELECT for the
column that was "duped", and in 0.8 an ambiguous column error
would be emitted.   The "keys" applied to the .c. collection
of the select() will also be deduped, so that the "column
being replaced" warning will no longer emit for any select()
that specifies use_labels, though the dupe key will be given
an anonymous label which isn't generally user-friendly.
[ticket:2702]
2013-04-11 16:14:23 -04:00
Mike Bayer af44efe26e Fixed a bug regarding column annotations which in particular
could impact some usages of the new :func:`.orm.remote` and
:func:`.orm.local` annotation functions, where annotations
could be lost when the column were used in a subsequent
expression.
[ticket:2660]
2013-02-02 20:06:31 -05:00
Mike Bayer eea0ca9fb4 cleanup and pep8 2013-02-02 19:57:45 -05:00
Mike Bayer 4950b85e83 - BinaryExpression now keeps track of "left" and "right" as passed in,
so that they can be compared in ``__nonzero__`` prior to their
self_group() step.  [ticket:2621]
2012-12-02 12:37:52 -05:00
Mike Bayer 6397a4ff4b Fixed bug in type_coerce() whereby typing information
could be lost if the statement were used as a subquery
inside of another statement, as well as other similar
situations.  Among other things, would cause
typing information to be lost when the Oracle/mssql dialects
would apply limit/offset wrappings. [ticket:2603]
2012-11-12 15:48:40 -05:00
Mike Bayer d30ab8495c Fixed bug whereby the ".key" of a Column wasn't being
used when producing a "proxy" of the column against
a selectable.   This probably didn't occur in 0.7
since 0.7 doesn't respect the ".key" in a wider
range of scenarios. [ticket:2597]
2012-10-31 14:30:47 -04:00
Mike Bayer a13812606c - remove remote_foreign annotation
- support annotations on Column where name isn't immediately present
2012-10-28 18:23:57 -04:00
Mike Bayer c307df6596 - [feature] "scalar" selects now have a WHERE method
to help with generative building.  Also slight adjustment
    regarding how SS "correlates" columns; the new methodology
    no longer applies meaning to the underlying
    Table column being selected.  This improves
    some fairly esoteric situations, and the logic
    that was there didn't seem to have any purpose.
  - [feature] Some support for auto-rendering of a
    relationship join condition based on the mapped
    attribute, with usage of core SQL constructs.
    E.g. select([SomeClass]).where(SomeClass.somerelationship)
    would render SELECT from "someclass" and use the
    primaryjoin of "somerelationship" as the WHERE
    clause.   This changes the previous meaning
    of "SomeClass.somerelationship" when used in a
    core SQL context; previously, it would "resolve"
    to the parent selectable, which wasn't generally
    useful.  Related to [ticket:2245].
2012-10-15 17:21:38 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 824bd66158 - aaaaand fix one more glitch I just thought of 2012-08-18 01:03:31 -04:00
Mike Bayer 54808ecccd - [bug] Declarative can now propagate a column
declared on a single-table inheritance subclass
up to the parent class' table, when the parent
class is itself mapped to a join() or select()
statement, directly or via joined inheritane,
and not just a Table.   [ticket:2549]
2012-08-15 18:42:59 -04:00
Mike Bayer f839b89270 - [feature] Added reduce_columns() method
to select() construct, replaces columns inline
    using the util.reduce_columns utility function
    to remove equivalent columns.  reduce_columns()
    also adds "with_only_synonyms" to limit the
    reduction just to those columns which have the same
    name.  The deprecated fold_equivalents() feature is
    removed [ticket:1729].
  - [feature] Added with_labels and
    reduce_columns keyword arguments to
    Query.subquery(), to provide two alternate
    strategies for producing queries with uniquely-
    named columns.  [ticket:1729].
2012-07-28 17:12:09 -04:00
Mike Bayer 27913554a8 trailing whitespace bonanza 2012-07-28 15:50:05 -04:00