Commit Graph

63 Commits

Author SHA1 Message Date
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
Mike Bayer de115ae406 - a big renaming of all the _Underscore classes to have
plain names.  The old names are still defined for
backwards compatibility.
- _BindParamClause renamed to BindParameter
2012-07-17 20:04:22 -04:00
Mike Bayer 81eefb2f13 - [bug] Fixed regression introduced in 0.7.6
whereby the FROM list of a SELECT statement
could be incorrect in certain "clone+replace"
scenarios.  [ticket:2518]
2012-06-21 14:55:04 -04:00
Mike Bayer 6a48ce44f4 - [bug] Fixed bug whereby append_column()
wouldn't function correctly on a cloned
select() construct, courtesy
Gunnlaugur Por Briem.  [ticket:2482]
Also in 0.7.8.
2012-06-16 19:02:48 -04:00
Mike Bayer 503bddc879 - [bug] column.label(None) now produces an
anonymous label, instead of returning the
column object itself, consistent with the behavior
of label(column, None).  [ticket:2168]
2012-04-24 13:04:38 -04:00
Mike Bayer 9b73e997b2 - [bug] The names of the columns on the
.c. attribute of a select().apply_labels()
is now based on <tablename>_<colkey> instead
of <tablename>_<colname>, for those columns
that have a distinctly named .key.
[ticket:2397]
2012-04-24 11:24:23 -04:00
Mike Bayer 713a4e19fa - merged #1401 branch from bitbucket
- resolved some serious speed hits I missed, we need to ensure
only deannotated columns are used in the local/remote collections and soforth
so that hash lookups against mapped columns don't dig into __eq__()
- fix some other parity mismatches regarding stuff from [ticket:2453],
including finding another case where _deep_annotate() was doing the wrong thing,
new tests.
- [feature] Major rewrite of relationship()
internals now allow join conditions which
include columns pointing to themselves
within composite foreign keys.   A new
API for very specialized primaryjoin conditions
is added, allowing conditions based on
SQL functions, CAST, etc. to be handled
by placing the annotation functions
remote() and foreign() inline within the
expression when necessary.  Previous recipes
using the semi-private _local_remote_pairs
approach can be upgraded to this new
approach. [ticket:1401]
2012-04-22 19:43:31 -04:00
Mike Bayer 1378bf0d25 - reopened #2453, needed to put in the original patch as well to cover the case
of column_property() objs building off each other
2012-04-03 09:59:22 -04:00
Mike Bayer 45046367f3 - [bug] Fixed bug in expression annotation
mechanics which could lead to incorrect
rendering of SELECT statements with aliases
and joins, particularly when using
column_property().  [ticket:2453]
2012-03-31 13:35:05 -04:00
Mike Bayer 57868f587e - [bug] Fixed bug whereby a primaryjoin
condition with a "literal" in it would
raise an error on compile with certain
kinds of deeply nested expressions
which also needed to render the same
bound parameter name more than once.
[ticket:2425]
2012-03-12 13:35:27 -07:00
Mike Bayer d934ea23e2 - figured out again why deannotate must clone()
- got everything working.  just need to update
error strings
2012-02-11 20:33:56 -05:00
Mike Bayer bc45fa350a - got m2m, local_remote_pairs, etc. working
- using new traversal that returns the product of both sides
of a binary, starting to work with (a+b) == (c+d) types of joins.
primaryjoins on functions working
- annotations working, including reversing local/remote when
doing backref
2012-02-09 21:16:53 -05:00
Mike Bayer 73f734bf80 initial annotations approach to join conditions. all tests pass, plus additional tests in #1401 pass.
would now like to reorganize RelationshipProperty more around the annotations concept.
2012-02-06 12:20:15 -05:00
Mike Bayer 2dbeeff50b - [bug] Added support for using the .key
of a Column as a string identifier in a
result set row.   The .key is currently
listed as an "alternate" name for a column,
and is superseded by the name of a column
which has that key value as its regular name.
For the next major release
of SQLAlchemy we may reverse this precedence
so that .key takes precedence, but this
is not decided on yet.  [ticket:2392]
2012-02-05 16:58:32 -05:00
Mike Bayer 699146086d - [bug] Fixed bug whereby column_property() created
against ORM-level column could be treated as
a distinct entity when producing certain
kinds of joined-inh joins.  [ticket:2316]

- [bug] related to [ticket:2316], made some
adjustments to the change from [ticket:2261]
regarding the "from" list on a select(). The
_froms collection is no longer memoized, as this
simplifies various use cases and removes the
need for a "warning" if a column is attached
to a table after it was already used in an
expression - the select() construct will now
always produce the correct expression.
There's probably no real-world
performance hit here; select() objects are
almost always made ad-hoc, and systems that
wish to optimize the re-use of a select()
would be using the "compiled_cache" feature.
A hit which would occur when calling select.bind
has been reduced, but the vast majority
of users shouldn't be using "bound metadata"
anyway :).
2011-12-03 19:50:01 -05:00
Mike Bayer c0c42af4e0 - [bug] further tweak to the fix from [ticket:2261],
so that generative methods work a bit better
off of cloned (this is almost a non-use case though).
In particular this allows with_only_columns()
to behave more consistently.   Added additional
documentation to with_only_columns() to clarify
expected behavior, which changed as a result
of [ticket:2261].  [ticket:2319]
- document the crap out of with_only_columns, include caveats about
the change, etc.
2011-11-19 23:28:01 -05:00
Mike Bayer 9d775a4cd4 - Fixed bug whereby with_only_columns() method of
Select would fail if a selectable were passed.
    [ticket:2270].  Also in 0.6.9.
2011-09-21 17:08:08 -04:00
Mike Bayer 1cf80dc5b2 - Changed the update() method on association proxy
dictionary to use a duck typing approach, i.e.
    checks for "keys", to discern between update({})
    and update((a, b)).   Previously, passing a
    dictionary that had tuples as keys would be misinterpreted
    as a sequence. [ticket:2275]
2011-09-14 11:31:33 -04:00
Mike Bayer 8c0e82238c - Fixed bug regarding calculation of "from" list
for a select() element.  The "from" calc is now
delayed, so that if the construct uses a Column
object that is not yet attached to a Table,
but is later associated with a Table, it generates
SQL using the table as a FROM.   This change
impacted fairly deeply the mechanics of how
the FROM list as well as the "correlates" collection
is calculated, as some "clause adaption" schemes
(these are used very heavily in the ORM)
were relying upon the fact that the "froms"
collection would typically be cached before the
adaption completed.   The rework allows it
such that the "froms" collection can be cleared
and re-generated at any time.  [ticket:2261]
- RelationshipProperty.Comparator._criterion_exists()
adds an "_orm_adapt" annotation to the correlates target,
to work with the change in [ticket:2261].   It's not clear
if the change to correlation+adaption mechanics will affect end user
code yet.
- FromClause now uses group_expirable_memoized_property for
late-generated values like primary key, _columns, etc.
The Select class adds some tokens to this object and has the
nice effect that FromClause doesn't need to know about
Select's names anymore.   An additional change might be to
have Select use a different group_expirable_memoized_property
so that it's collection of attribute names are specific to
Select though this isn't really necessary right now.
2011-09-05 19:12:12 -04:00
Mike Bayer 5c7cc27425 - rework Annotated to no longer use __cmp__(), supply an __eq__() that
works with ColumnElement as well as works with non-__eq__() suppliers,
works with sets, on Py3K as well.
2011-07-24 20:41:42 -04:00
Mike Bayer 8a483dbf38 - rewrite cloned_traverse() and replacement_traverse() to use a straight
recursive descent with clone() + _copy_internals().  This is essentially
what it was doing anyway with lots of unnecessary steps.
Fix Alias() to honor the given clone() function which may have been the
reason the traversal hadn't been fixed sooner.   Alias._copy_internals()
will specifically skip an alias of a Table
as a more specific form of what it was doing before.  This may need to
be further improved such that ClauseAdapter or replacement_traverse()
send it some specific hints what not to dig into; **kw has been added
to all _copy_internals() to support this.   replacement/clone traversal
is at least clear now.
- apply new no_replacement_traverse annotation to join created by
_create_joins(), fixes [ticket:2195]
- can replace orm.query "_halt_adapt" with "no_replacement_traverse"
2011-07-24 17:51:01 -04:00
Mike Bayer 668991a7ed - Fixed subtle bug that caused SQL to blow
up if: column_property() against subquery +
joinedload + LIMIT + order by the column
property() occurred.  [ticket:2188].
Also in 0.6.9
2011-06-27 19:25:35 -04:00
Mike Bayer 63dbed1fd7 - Fixed a subtle bug involving column
correspondence in a selectable with the
    same column repeated.   Affects [ticket:2188].
2011-06-27 18:54:02 -04:00
Mike Bayer 50a96ca260 use default dialect here 2011-05-29 13:50:41 -04:00
Mike Bayer 736481e58f - Streamlined the process by which a Select
determines what's in it's '.c' collection.
Behaves identically, except that a
raw ClauseList() passed to select([])
(which is not a documented case anyway) will
now be expanded into its individual column
elements instead of being ignored.
2011-05-28 13:28:38 -04:00
Mike Bayer 00380cf3c3 - Fixed bug whereby nesting a label of a select()
with another label in it would produce incorrect
exported columns.   Among other things this would
break an ORM column_property() mapping against
another column_property().  [ticket:2167].
Also in 0.6.8
- _Label() is always against a column or selectable.  remove
uncovered case of label against something else.
- start taking notes to clean up some of this labeling stuff,
which will be [ticket:2168]
2011-05-18 12:07:40 -04:00
Mike Bayer 4bc2402cc0 - Changed the handling in determination of join
conditions such that foreign key errors are
only considered between the two given tables.
That is, t1.join(t2) will report FK errors
that involve 't1' or 't2', but anything
involving 't3' will be skipped.   This affects
join(), as well as ORM relationship and
inherit condition logic.  Will keep the more conservative
approach to [ticket:2153] in 0.6.
2011-05-07 12:52:25 -04:00