summaryrefslogtreecommitdiff
path: root/test/sql/test_generative.py
Commit message (Collapse)AuthorAgeFilesLines
* Add anonymizing context to cache keys, comparison; convert traversalMike Bayer2019-11-041-2095/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Created new visitor system called "internal traversal" that applies a data driven approach to the concept of a class that defines its own traversal steps, in contrast to the existing style of traversal now known as "external traversal" where the visitor class defines the traversal, i.e. the SQLCompiler. The internal traversal system now implements get_children(), _copy_internals(), compare() and _cache_key() for most Core elements. Core elements with special needs like Select still implement some of these methods directly however most of these methods are no longer explicitly implemented. The data-driven system is also applied to ORM elements that take part in SQL expressions so that these objects, like mappers, aliasedclass, query options, etc. can all participate in the cache key process. Still not considered is that this approach to defining traversibility will be used to create some kind of generic introspection system that works across Core / ORM. It's also not clear if real statement caching using the _cache_key() method is feasible, if it is shown that running _cache_key() is nearly as expensive as compiling in any case. Because it is data driven, it is more straightforward to optimize using inlined code, as is the case now, as well as potentially using C code to speed it up. In addition, the caching sytem now accommodates for anonymous name labels, which is essential so that constructs which have anonymous labels can be cacheable, that is, their position within a statement in relation to other anonymous names causes them to generate an integer counter relative to that construct which will be the same every time. Gathering of bound parameters from any cache key generation is also now required as there is no use case for a cache key that does not extract bound parameter values. Applies-to: #4639 Change-Id: I0660584def8627cad566719ee98d3be045db4b8d
* Unify generation between Core and ORM queryMike Bayer2019-09-261-4/+4
| | | | | | | | | | | | | | generation is to be enhanced to include caching functionality, so ensure that Query and all generative in Core (e.g. select, DML etc) are using the same generations system. Additionally, deprecate Select.append methods and state Select methods independently of their append versions. Mutability of expression objects is a special case only when generating new objects during a visit. Fixes: #4637 Change-Id: I3dfac00d5e0f710c833b236f7a0913e1ca24dde4
* Adjustments to _copy_internals()Mike Bayer2019-09-061-3/+13
| | | | | | | | | | | | We are looking to build a generalization of copy_internals(), so move out any special logic from these methods. Re-implement and clarify rationale for the Alias doesnt copy a TableClause rule as part of the adaption traversal, establish that we forgot to build out comparison and cache key for CTE, remove incomplete _copy_internals() from GenerativeSelect (it doesn't handle the order_by_clause or group_by_clause, so is incomplete) Change-Id: I95039f042503171aade4ba0fabc9b1598e3c49cf
* Add additional tests to verify _is_clone_of proxy level linkMike Bayer2019-08-011-6/+7
| | | | | | | | | | | | The commit message in 896d47f318c5c27620fd6da is not accurate, we do in fact still need _is_clone_of when a clone of a column is created so that we can implement _cloned_set(). Additionally, the linkage of _is_clone_of within make_proxy() also suits an additional use case that seems to be related to [ticket:2419]. Adjust one of the tests which likely got changed within 1.4's refactoring of Select to test this correctly. Change-Id: I124c7c6b02498e2dfad9797816df42a5b6f91901
* SelectBase no longer a FromClauseMike Bayer2019-07-061-34/+52
| | | | | | | | | | | | | | | | | | | | As part of the SQLAlchemy 2.0 migration project, a conceptual change has been made to the role of the :class:`.SelectBase` class hierarchy, which is the root of all "SELECT" statement constructs, in that they no longer serve directly as FROM clauses, that is, they no longer subclass :class:`.FromClause`. For end users, the change mostly means that any placement of a :func:`.select` construct in the FROM clause of another :func:`.select` requires first that it be wrapped in a subquery first, which historically is through the use of the :meth:`.SelectBase.alias` method, and is now also available through the use of :meth:`.SelectBase.subquery`. This was usually a requirement in any case since several databases don't accept unnamed SELECT subqueries in their FROM clause in any case. See the documentation in this change for lots more detail. Fixes: #4617 Change-Id: I0f6174ee24b9a1a4529168e52e855e12abd60667
* Enable F841Mike Bayer2019-06-201-25/+14
| | | | | | | | | | | This is a very useful assertion which prevents unused variables from being set up allows code to be more readable and sometimes even more efficient. test suites seem to be where the most problems are and there do not seem to be documentation examples that are using this, or at least the linter is not taking effect within rst blocks. Change-Id: I2b3341d8dd14da34879d8425838e66a4b9f8e27d
* Implement new ClauseElement role and coercion systemMike Bayer2019-05-181-19/+25
| | | | | | | | | | | | | | | | | | | | A major refactoring of all the functions handle all detection of Core argument types as well as perform coercions into a new class hierarchy based on "roles", each of which identify a syntactical location within a SQL statement. In contrast to the ClauseElement hierarchy that identifies "what" each object is syntactically, the SQLRole hierarchy identifies the "where does it go" of each object syntactically. From this we define a consistent type checking and coercion system that establishes well defined behviors. This is a breakout of the patch that is reorganizing select() constructs to no longer be in the FromClause hierarchy. Also includes a rename of as_scalar() into scalar_subquery(); deprecates automatic coercion to scalar_subquery(). Partially-fixes: #4617 Change-Id: I26f1e78898693c6b99ef7ea2f4e7dfd0e8e1a1bd
* Clone internals for Select._correlate_except collection as well as _correlateMike Bayer2019-03-101-0/+84
| | | | | | | | | | | | | | Fixed bug where use of :func:`.with_polymorphic` or other aliased construct would not properly adapt when the aliased target were used as the :meth:`.Select.correlate_except` target of a subquery used inside of a :func:`.column_property`. This required a fix to the clause adaption mechanics to properly handle a selectable that shows up in the "correlate except" list, in a similar manner as which occurs for selectables that show up in the "correlate" list. This is ultimately a fairly fundamental bug that has lasted for a long time but it is hard to come across it. Fixes: #4537 Change-Id: Ibb97d4eea18b3c452aad519dd14919bfb84d422f
* Add getters for all execution_optionsDaniel Lister2019-01-251-3/+3
| | | | | | | | | | | | | | | Added accessors for execution options to Core and ORM, via :meth:`.Query.get_execution_options`, :meth:`.Connection.get_execution_options`, :meth:`.Engine.get_execution_options`, and :meth:`.Executable.get_execution_options`. PR courtesy Daniel Lister. Fixes: #4406 Closes: #4465 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4465 Pull-request-sha: 9674688bb5e80471a6a421bac06f995c2e64f8f7 Change-Id: I93ba51d7a2d687e255edd6938db15615e56dd237
* Add deprecation warnings to all deprecated APIsMike Bayer2019-01-231-2/+2
| | | | | | | | | | | | | | | A large change throughout the library has ensured that all objects, parameters, and behaviors which have been noted as deprecated or legacy now emit ``DeprecationWarning`` warnings when invoked. As the Python 3 interpreter now defaults to displaying deprecation warnings, as well as that modern test suites based on tools like tox and pytest tend to display deprecation warnings, this change should make it easier to note what API features are obsolete. See the notes added to the changelog and migration notes for further details. Fixes: #4393 Change-Id: If0ea11a1fc24f9a8029352eeadfc49a7a54c0a1b
* Post black reformattingMike Bayer2019-01-061-43/+40
| | | | | | | | | | | | | 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
* Run black -l 79 against all source filesMike Bayer2019-01-061-755/+787
| | | | | | | | | | | | | | 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
* Track if we're rendering within the CTE recursivelyMike Bayer2018-03-141-1/+1
| | | | | | | | | | Fixed a regression that occurred from the previous fix to :ticket:`4204` in version 1.2.5, where a CTE that refers to itself after the :meth:`.CTE.alias` method has been called would not refer to iself correctly. Change-Id: Iaa63d65ad2b90c8693f9953fbb32dbb10c73a037 Fixes: #4204
* Clone _cte_alias instead of assigning "self"Mike Bayer2018-03-051-0/+16
| | | | | | | | | | Fixed bug in :class:.`CTE` construct along the same lines as that of :ticket:`4204` where a :class:`.CTE` that was aliased would not copy itself correctly during a "clone" operation as is frequent within the ORM as well as when using the :meth:`.ClauseElement.params` method. Change-Id: Id68d72dd244dedfc7bd6116c9a5123c51a55ea20 Fixes: #4210
* Repair WithinGroup.get_children()Mike Bayer2017-06-161-0/+10
| | | | | | | | Fixed AttributeError which would occur in :class:`.WithinGroup` construct during an iteration of the structure. Change-Id: I563882d93c8c32292463a605b636aa60c77e9406 Fixes: #4012
* Make all tests to be PEP8 compliantKhairi Hafsham2017-02-071-27/+35
| | | | | | | | tested using pycodestyle version 2.2.0 Fixes: #3885 Change-Id: I5df43adc3aefe318f9eeab72a078247a548ec566 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/343
* Spelling fixesVille Skyttä2016-10-081-2/+2
|
* Ensure CTE internals are handled during cloneMike Bayer2016-06-101-0/+17
| | | | | | | | | The CTE construct was missing a _copy_internals() method which would handle CTE-specific structures including _cte_alias, _restates during a clone operation. Change-Id: I9aeac9cd24d8f7ae6b70e52650d61f7c96cb6d7e Fixes: #3722
* - Fixed a bug where clause adaption as applied to a :class:`.Label`Mike Bayer2015-06-091-0/+21
| | | | | | | | | | | | object would fail to accommodate the labeled SQL expression in all cases, such that any SQL operation that made use of :meth:`.Label.self_group` would use the original unadapted expression. One effect of this would be that an ORM :func:`.aliased` construct would not fully accommodate attributes mapped by :obj:`.column_property`, such that the un-aliased table could leak out when the property were used in some kinds of SQL comparisons. fixes #3445
* PEP8 cleanup in /test/sqlEric Streeper2015-03-181-2/+0
|
* - Fixed bug regarding expression mutations which could expressMike Bayer2014-11-051-0/+13
| | | | | | | | itself as a "Could not locate column" error when using :class:`.Query` to select from multiple, anonymous column entities when querying against SQLite, as a side effect of the "join rewriting" feature used by the SQLite dialect. fixes #3241
* renamed aggregatefilter to funcfilter, since it is thatIlja Everilä2014-09-111-1/+1
|
* add ClauseTest for aggregatefilterIlja Everilä2014-09-101-0/+5
|
* - rework ColumnAdapter and ORMAdapter to only provide the featuresticket_3148Mike Bayer2014-09-071-2/+262
| | | | | | | | | | | 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
* - enhance ClauseAdapter / ColumnAdapter to have new behaviors with labels.Mike Bayer2014-09-071-0/+46
| | | | | | | | | | | | | | | | | | | | | The "anonymize label" logic is now generalized to ClauseAdapter, and takes place when the anonymize_labels flag is sent, taking effect for all .columns lookups as well as within traverse() calls against the label directly. - traverse() will also memoize what it gets in columns, so that calling upon traverse() / .columns against the same Label will produce the same anonymized label. This is so that AliasedClass produces the same anonymized label when it is accessed per-column (e.g. SomeAlias.some_column) as well as when it is applied to a Query, and within column loader strategies (e.g. query(SomeAlias)); the former uses traverse() while the latter uses .columns - AliasedClass now calls onto ColumnAdapter - Query also makes sure to use that same ColumnAdapter from the AliasedClass in all cases - update the logic from 0.9 in #1068 to make use of the same _label_resolve_dict we use for #2992, simplifying how that works and adding support for new scenarios that were pretty broken (see #3148, #3188)
* - The :func:`~.expression.column` and :func:`~.expression.table`Mike Bayer2014-09-011-22/+22
| | | | | | | | | | | | | | | | | | | | | constructs are now importable from the "from sqlalchemy" namespace, just like every other Core construct. - The implicit conversion of strings to :func:`.text` constructs when passed to most builder methods of :func:`.select` as well as :class:`.Query` now emits a warning with just the plain string sent. The textual conversion still proceeds normally, however. The only method that accepts a string without a warning are the "label reference" methods like order_by(), group_by(); these functions will now at compile time attempt to resolve a single string argument to a column or label expression present in the selectable; if none is located, the expression still renders, but you get the warning again. The rationale here is that the implicit conversion from string to text is more unexpected than not these days, and it is better that the user send more direction to the Core / ORM when passing a raw string as to what direction should be taken. Core/ORM tutorials have been updated to go more in depth as to how text is handled. fixes #2992
* - update the flake8 rules againMike Bayer2014-07-181-226/+294
| | | | - apply autopep8 + manual fixes to most of test/sql/
* Fix many typos throughout the codebasepr/85Alex Gaynor2014-04-261-1/+1
| | | | Found using: https://github.com/intgr/topy
* - New improvements to the :func:`.text` construct, includingMike Bayer2013-11-291-3/+3
| | | | | | | | more flexible ways to set up bound parameters and return types; in particular, a :func:`.text` can now be turned into a full FROM-object, embeddable in other statements as an alias or CTE using the new method :meth:`.TextClause.columns`. [ticket:2877]
* - the raw 2to3 runMike Bayer2013-04-271-8/+8
| | | | - went through examples/ and cleaned out excess list() calls
* - the base correlate tests in test_compiler cover the ones that were hereMike Bayer2013-03-091-127/+79
| | | | | for now - fix up adaptation tests to still try to exercise the correlation argument
* go back to the original form, then break out this test into individualsMike Bayer2013-03-081-53/+115
| | | | so it can be managed more easily
* Changed behavior of Select.correlate() to ignore correlations to froms that ↵Luke Cyca2013-03-071-40/+47
| | | | don't exist in the superquery.
* - multivalued inserts, [ticket:2623]Mike Bayer2012-12-081-4/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - update "not supported" messages for empty inserts, mutlivalue inserts - rework the ValuesBase approach for multiple value sets so that stmt.parameters does store a list for multiple values; the _has_multiple_parameters flag now indicates which of the two modes the statement is within. it now raises exceptions if a subsequent call to values() attempts to call a ValuesBase with one mode in the style of the other mode; that is, you can't switch a single- or multi- valued ValuesBase to the other mode, and also if a multiple value is passed simultaneously with a kwargs set. Added tests for these error conditions - Calling values() multiple times in multivalue mode now extends the parameter list to include the new parameter sets. - add error/test if multiple *args were passed to ValuesBase.values() - rework the compiler approach for multivalue inserts, back to where _get_colparams() returns the same list of (column, value) as before, thereby maintaining the identical number of append() and other calls when multivalue is not enabled. In the case of multivalue, it makes a last-minute switch to return a list of lists instead of the single list. As it constructs the additional lists, the inline defaults and other calculated default parameters of the first parameter set are copied into the newly generated lists so that these features continue to function for a multivalue insert. Multivalue inserts now add no additional function calls to the compilation for regular insert constructs. - parameter lists for multivalue inserts now includes an integer index for all parameter sets. - add detailed documentation for ValuesBase.values(), including careful wording to describe the difference between multiple values and an executemany() call. - add a test for multivalue insert + returning - it works ! - remove the very old/never used "postgresql_returning"/"firebird_returning" flags.
* - get 100% lint/pep8 happening for test_compiler; next we will beginMike Bayer2012-10-241-31/+28
| | | | | | cutting up tests and removing old ones - move test_in() to test_operators - slice up migrated operator tests into TOT
* The auto-correlation feature of :func:`.select`, andMike Bayer2012-10-221-26/+45
| | | | | | | | | by proxy that of :class:`.orm.Query`, will not take effect for a SELECT statement that is being rendered directly in the FROM list of the enclosing SELECT. Correlation in SQL only applies to column expressions such as those in the WHERE, ORDER BY, columns clause. [ticket:2595]
* trying different approaches to test layout. in this one, the testing modulesMike Bayer2012-09-271-3/+6
| | | | | | | 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.
* -whitespace bonanza, contdMike Bayer2012-07-281-32/+32
|
* - merged #1401 branch from bitbucketMike Bayer2012-04-221-1/+97
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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]
| * tweak for correlated subqueries here, seems to work for ↵Mike Bayer2012-02-101-0/+12
| | | | | | | | test_eager_relations:CorrelatedSubqueryTest but need some more testing here
| * - got m2m, local_remote_pairs, etc. workingMike Bayer2012-02-091-1/+85
| | | | | | | | | | | | | | | | - 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
* | - expand the check to determine if a selectable column is embeddedMike Bayer2012-02-291-2/+80
|/ | | | | | | | | | in the corresponding selectable to take into account clones of the target column. fixes [ticket:2419] - have _make_proxy() copy out the _is_clone_of attribute on the new column so that even more corresponding_column() checks work as expected for cloned elements. - add a new test fixture so that mapped tests can be specified using declarative.
* - rewrite cloned_traverse() and replacement_traverse() to use a straightMike Bayer2011-07-241-1/+12
| | | | | | | | | | | | | | | | 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"
* - move documentation of available execution options to Connection - this is ↵Mike Bayer2011-04-171-2/+14
| | | | | | | | | | the main place these should be used - Executable disallows "compiled_cache" option for now which was previously being ignored [ticket:2131] - Query now passes execution options to the Connection rather than the statement so that all options are allowed including compiled cache.
* - remove test.sql._base, test.engine._base, test.orm._base, move those ↵Mike Bayer2011-03-271-6/+6
| | | | | | | classes to a new test.lib.fixtures module - move testing.TestBase to test.lib.fixtures - massive search and replace
* make it more explicit in tests which dialect we want to use for thingsMike Bayer2011-02-111-0/+10
|
* fix some really egregious long linesMike Bayer2011-02-101-206/+437
|
* - Added over() function, method to FunctionElementMike Bayer2011-02-101-0/+5
| | | | | | | | classes, produces the _Over() construct which in turn generates "window functions", i.e. "<window function> OVER (PARTITION BY <partition by>, ORDER BY <order by>)". [ticket:1844]
* - whitespace removal bonanzaMike Bayer2011-01-021-55/+55
|
* - sqlalchemy.test and nose plugin moves back to being entirelyMike Bayer2010-11-281-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | outside of "sqlalchemy" and under "test/". Rationale: - coverage plugin works without issue, without need for an awkward additional package install - command line for "nosetests" isn't polluted with SQLAlchemy options [ticket:1949]