Commit Graph

108 Commits

Author SHA1 Message Date
Nicolas CANIART d91edf2511 Accommodate tuples for ColumnDefault.__repr__
Fixed bug where ``__repr__`` of :class:`.ColumnDefault` would fail
if the argument were a tuple.  Pull request courtesy Nicolas Caniart.

Change-Id: I08aa2448ef91054c43d6068ac54cedbdf7a83d64
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/1
Fixes: #4126
(cherry picked from commit 5acc9b149a)
2017-10-31 11:40:00 -04:00
Mike Bayer 0769b41cf2 Raise if ForeignKeyConstraint created with different numbers of
local and remote columns.

An :class:`.ArgumentError` is now raised if a
:class:`.ForeignKeyConstraint` object is created with a mismatched
number of "local" and "remote" columns, which otherwise causes the
internal state of the constraint to be incorrect.   Note that this
also impacts the condition where a dialect's reflection process
produces a mismatched set of columns for a foreign key constraint.

Downstream DB2 dialect has been reported as potentially causing this
scenario.

Change-Id: Id51c34a6c43749bb582639f9c1dc28723482f0e5
Fixes: #3949
References: #3998
(cherry picked from commit a78718b934)
2017-05-25 16:25:09 -04:00
Mike Bayer c04870ba7b Allow SchemaType and Variant to work together
Added support for the :class:`.Variant` and the :class:`.SchemaType`
objects to be compatible with each other.  That is, a variant
can be created against a type like :class:`.Enum`, and the instructions
to create constraints and/or database-specific type objects will
propagate correctly as per the variant's dialect mapping.

Also added testing for some potential double-event scenarios
on TypeDecorator but it seems usually this doesn't occur.

Change-Id: I4a7e7c26b4133cd14e870f5bc34a1b2f0f19a14a
Fixes: #2892
2017-03-07 16:24:18 -05:00
Mike Bayer 9e62715973 Repair missing "checkfirst" for test suite
the test_metadata tests trigger the before_create dispatch without
the checkfirst flag.  Postgresql backend should be able to
tolerate this.

Change-Id: Ife497cc3a4eb2812462116f94aad732864225f3f
2017-03-07 15:00:18 -05: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 fa6dd376bb Support python3.6
Corrects some warnings and adds tox config.  Adds DeprecationWarning
to the error category.   Large sweep for string literals w/ backslashes
as this is common in docstrings

Co-authored-by: Andrii Soldatenko
Fixes: #3886
Change-Id: Ia7c838dfbbe70b262622ed0803d581edc736e085
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/337
2017-01-13 10:57:41 -05:00
Mike Bayer 30bd28fca2 Ensure TypeDecorator delegates _set_parent_with_dispatch
Ensure TypeDecorator delegates _set_parent_with_dispatch as well as
_set_parent to itself as well as its impl, as the TypeDecorator
class itself may have an active SchemaType implementation as well.

Fixed regression which occurred as a side effect of 🎫`2919`,
which in the less typical case of a user-defined
:class:`.TypeDecorator` that was also itself an instance of
:class:`.SchemaType` (rather than the implementation being such)
would cause the column attachment events to be skipped for the
type itself.

Change-Id: I0afb498fd91ab7d948e4439e7323a89eafcce0bc
Fixes: #3832
2016-10-20 14:14:50 -04:00
Mike Bayer 8ef4f6a538 Add explicit copy() to Enum
The Boolean and Enum types both place SchemaType second in the
inheritance hierarchy.  In the case of Enum, this works
out that the copy() method is called from the base TypeEngine
which fails to transfer _create_events.   The test suite
doesn't seem to work with the inhertance hierarchy set up like
this as the event listeners don't work out, the _on_metadata_create
and _on_table_create hooks cause the production of an adapted type
which then adds event listeners that cause deque changed while
iteration.  It's not clear why Enum /Boolean don't have this problem.
But in any case it seems like the class mechanics for these types
remains fragile and would benefit from yet another refactor someday.

Change-Id: Ib641a5d2321b00f58bbe98dd0c5e789374db32b2
Fixes: #3827
2016-10-17 12:13:01 -04:00
Mike Bayer 1269b08b1b Ensure post-__clause_element__() expression are used in Index
The change in Index for 1.1 combined with the fix for
ref #3763 still fails to deliver the correct object
resolved by __clause_element__() to the list of expressions
for compilation.   Make sure we use the expression that's
been unwrapped from __clause_element__().

Change-Id: Ie1df8db5090de665048331786f0024d52851923f
Fixes: #3763
2016-07-31 00:10:04 -04:00
Mike Bayer 6327c59d4f Index should extract __clause_element__() early
Fixed bug where :class:`.Index` would fail to extract columns from
compound SQL expressions if those SQL expressions were wrapped inside
of an ORM-style ``__clause_element__()`` construct.  This bug
exists in 1.0.x as well, however in 1.1 is more noticeable as
hybrid_property @expression now returns a wrapped element.

Fixes: #3763

Change-Id: I992536386503a1fb3f2305790abe008d72c44c4a
2016-07-30 10:11:53 -04:00
Mike Bayer e467e899e1 - Consoliate test/sql/test_constraint ConstraintAPITest
and test/sql/test_metadata IndexTest into
test/sql/test_metadata ConstraintTest

Change-Id: I7aeee9a1edbbd889200afc393695f73d5fbac3f3
2016-07-30 10:06:53 -04:00
Mike Bayer 2c8643b0e9 Allow Table._reset_exported to silently pass
Fixed bug in :class:`.Table` where the internal method
``_reset_exported()`` would corrupt the state of the object.  This
method is intended for selectable objects and is called by the ORM
in some cases; an erroneous mapper configuration would could lead the
ORM to call this on on a :class:`.Table` object.

Change-Id: I63fa34ee0cdf16358bb125c556390df79758bcbc
Fixes: #3755
2016-07-24 23:17:11 -04:00
Mike Bayer f38f890849 Deprecate FromClause.count()
count() here is misleading in that it not only
counts from an arbitrary column in the table, it also
does not make accommodations for DISTINCT, JOIN, etc.
as the ORM-level function does.  Core should not be
attempting to provide a function like this.

Change-Id: I9916fc51ef744389a92c54660ab08e9695b8afc2
Fixes: #3724
2016-06-14 11:48:04 -04:00
Mike Bayer afb466fb8b Skip UniqueConstraint marked by unique=True in tometadata
Fixes an issue where a Column would be copied with unique=True
and at the same time the UniqueConstraint would also be copied,
leading to duplicate UniqueConstraints in the target table,
when tometadata() is used.   Imitates the same logic used
by index=True/Index to avoid duplicates.  For some reason
a fix was implemented for Index long ago but never for
UniqueConstraint.

Change-Id: Ie622ee912a6fb8bf0ea900a8b09d78c7ebc79fc0
Fixes: #3721
2016-06-02 13:54:07 -04:00
Mike Bayer c124fa36d5 Support "blank" schema when MetaData.schema is set
Previously, it was impossible to have a Table that has
None for a schema name when the "schema" parameter on
MetaData was set.  A new symbol sqlalchemy.schema.BLANK_SCHEMA
is added which indicates that the schema name should unconditionally
be set to None.  In particular, this value must be passed within
cross-schema foreign key reflection, so that a Table which
is in the "default" schema can be represented properly.

Fixes: #3716
Change-Id: I3d24f99c22cded206c5379fd32a225e74edb7a8e
2016-05-18 11:43:38 -04:00
Mike Bayer 8163de4cc9 - rework ColumnCollection to no longer persist "all_col_set"; we don't
need this collection except in the extend/update uses where we
create it ad-hoc.  simplifies pickling.  Compatibility with 1.0
should be OK as ColumnColleciton uses __getstate__ in any case
and the __setstate__ contract hasn't changed.
- Fixed bug in :class:`.Table` metadata construct which appeared
around the 0.9 series where adding columns to a :class:`.Table`
that was unpickled would fail to correctly establish the
:class:`.Column` within the 'c' collection, leading to issues in
areas such as ORM configuration.   This could impact use cases such
as ``extend_existing`` and others.  fixes #3632
2016-01-26 16:41:26 -05: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 c7d6c667b5 - Fixed an assertion that would raise somewhat inappropriately
if a :class:`.Index` were associated with a :class:`.Column` that
is associated with a lower-case-t :class:`.TableClause`; the
association should be ignored for the purposes of associating
the index with a :class:`.Table`.
fixes #3616
2015-12-23 22:59:44 -05:00
Mike Bayer 37565d2ce2 - fix missing argument in TypeDecorator.copy(), fixes #3584, references #2919 2015-11-13 11:01:49 -05:00
Mike Bayer 845500280d - open up autoincrement for columns that have a default; autoinc is usually
"auto" now so True can indicate the dialect would support this
2015-10-08 17:02:55 -04:00
Mike Bayer 414af7b612 - The system by which a :class:.Column considers itself to be an
"auto increment" column has been changed, such that autoincrement
is no longer implicitly enabled for a :class:`.Table` that has a
composite primary key.  In order to accommodate being able to enable
autoincrement for a composite PK member column while at the same time
maintaining SQLAlchemy's long standing behavior of enabling
implicit autoincrement for a single integer primary key, a third
state has been added to the :paramref:`.Column.autoincrement` parameter
``"auto"``, which is now the default. fixes #3216
- The MySQL dialect no longer generates an extra "KEY" directive when
generating CREATE TABLE DDL for a table using InnoDB with a
composite primary key with AUTO_INCREMENT on a column that isn't the
first column;  to overcome InnoDB's limitation here, the PRIMARY KEY
constraint is now generated with the AUTO_INCREMENT column placed
first in the list of columns.
2015-10-07 10:02:45 -04:00
Mike Bayer 623e5b2149 Merge remote-tracking branch 'origin/pr/163' into pr163 2015-04-12 14:56:15 -04:00
Mike Bayer 55c26710a1 - Fixed issue where a :class:.MetaData object that used a naming
convention would not properly work with pickle.  The attribute was
skipped leading to inconsistencies and failures if the unpickled
:class:`.MetaData` object were used to base additional tables
from.
fixes #3362
2015-04-10 11:20:14 -04:00
Eric Streeper e467db9edb PEP8 cleanup in /test/sql 2015-03-18 21:38:57 -07:00
Sebastian Bank b3f9698c63 make sort_tables order deterministic 2015-03-07 14:04:14 +01:00
Mike Bayer 383bb3f708 - The :class:.CheckConstraint construct now supports naming
conventions that include the token ``%(column_0_name)s``; the
constraint expression is scanned for columns.  Additionally,
naming conventions for check constraints that don't include the
``%(constraint_name)s`` token will now work for :class:`.SchemaType`-
generated constraints, such as those of :class:`.Boolean` and
:class:`.Enum`; this stopped working in 0.9.7 due to 🎫`3067`.
fixes #3299
2015-01-30 13:38:51 -05:00
Mike Bayer 3712e35c32 - Fixed bug in 0.9's foreign key setup system, such that
the logic used to link a :class:`.ForeignKey` to its parent could fail
when the foreign key used "link_to_name=True" in conjunction with
a target :class:`.Table` that would not receive its parent column until
later, such as within a reflection + "useexisting" scenario,
if the target column in fact had a key value different from its name,
as would occur in reflection if column reflect events were used to
alter the .key of reflected :class:`.Column` objects so that the
link_to_name becomes significant.  Also repaired support for column
type via FK transmission in a similar way when target columns had a
different key and were referenced using link_to_name.
fixes #3298
2015-01-28 11:55:26 -05:00
Mike Bayer 8f5e4acbf6 - Added a new accessor :attr:.Table.foreign_key_constraints
to complement the :attr:`.Table.foreign_keys` collection,
as well as :attr:`.ForeignKeyConstraint.referred_table`.
2015-01-01 13:39:42 -05:00
Mike Bayer c24423bc2e - enhance only_on() to work with compound specs
- fix "temporary_tables" requirement
2014-12-06 13:33:57 -05:00
Mike Bayer 156f473de0 Merge remote-tracking branch 'origin/pr/151' into pr151 2014-12-01 13:31:48 -05:00
Mike Bayer 98c2a67970 - Fixed bug in :meth:.Table.tometadata method where the
:class:`.CheckConstraint` associated with a :class:`.Boolean`
or :class:`.Enum` type object would be doubled in the target table.
The copy process now tracks the production of this constraint object
as local to a type object.
fixes #3260
2014-11-29 14:46:34 -05:00
Mike Bayer 212d93366d - The behavioral contract of the :attr:.ForeignKeyConstraint.columns
collection has been made consistent; this attribute is now a
:class:`.ColumnCollection` like that of all other constraints and
is initialized at the point when the constraint is associated with
a :class:`.Table`.
fixes #3243
2014-11-25 18:01:31 -05:00
Scott Dugas b31ab00689 Merge branch 'master' into fdbsql-tests
Conflicts:
	lib/sqlalchemy/testing/exclusions.py
2014-11-03 14:54:51 -05:00
Scott Dugas 5b3fc87435 Added requirement for temporary tables 2014-10-30 11:06:45 -04:00
Scott Dugas fdbea87958 require check constraints for tests 2014-10-23 17:59:27 -04:00
Mike Bayer 56d5732fbd - changelog for pullreq github:139
- add support for self-referential foreign keys to move over as well when
the table name is changed.
2014-10-21 17:58:51 -04:00
Mike Bayer 0ae140aa98 Merge remote-tracking branch 'origin/pr/139' into pr139 2014-10-21 17:29:40 -04:00
ndparker 7e0835409c add simple tests for new name argument for Table.tometadata() 2014-10-04 00:51:01 +02:00
Mike Bayer 19ec6c3368 - "column already assigned" message has been updated in 7f82c55f 2014-09-25 21:16:13 -04:00
Mike Bayer 2c46128a2f - use compat.u for python3.2, fixes #3198 2014-09-15 14:57:41 -04:00
Mike Bayer d768ec2c26 - don't add the parent attach event within _on_table_attach
if we already have a table; this prevents reentrant calls and
we aren't supporting columns/etc being moved around between different parents
2014-08-15 14:27:12 -04:00
Mike Bayer 7fc08fe89a - The `info` parameter has been added to the constructor for
:class:`.SynonymProperty` and :class:`.ComparableProperty`.
- The ``info`` parameter has been added as a constructor argument
to all schema constructs including :class:`.MetaData`,
:class:`.Index`, :class:`.ForeignKey`, :class:`.ForeignKeyConstraint`,
:class:`.UniqueConstraint`, :class:`.PrimaryKeyConstraint`,
:class:`.CheckConstraint`.

fixes #2963
2014-08-13 19:45:34 -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 f4653729a6 - wrestle with conv() and tests some more 2014-07-14 22:44:33 -04:00
Mike Bayer dbc8bbfba3 - allow the compilation rule that gets the formatted name
to again have the chance to veto rendering, as the naming convention
can make the decision that the name is "none" or not now.
2014-07-14 21:11:51 -04:00
Mike Bayer d2193f53c1 - Fix bug in naming convention feature where using a check
constraint convention that includes ``constraint_name`` would
then force all :class:`.Boolean` and :class:`.Enum` types to
require names as well, as these implicitly create a
constraint, even if the ultimate target backend were one that does
not require generation of the constraint such as Postgresql.
The mechanics of naming conventions for these particular
constraints has been reorganized such that the naming
determination is done at DDL compile time, rather than at
constraint/table construction time.
fixes #3067
2014-07-14 20:26:38 -04:00
Mike Bayer a49ec1cf77 - Added a "str()" step to the dialect_kwargs iteration for
Python version < 2.6.5, working around the
"no unicode keyword arg" bug as these args are passed along as
keyword args within some reflection processes.
fixes #3123
2014-07-14 18:09:54 -04:00
Mike Bayer 071a183098 - Fixed bug in :class:.Enum and other :class:.SchemaType
subclasses where direct association of the type with a
:class:`.MetaData` would lead to a hang when events
(like create events) were emitted on the :class:`.MetaData`.
fixes #3124
2014-07-13 18:55:18 -04:00
Mike Bayer bd56485f4c - The :paramref:.Column.nullable flag is implicitly set to `False`
when that :class:`.Column` is referred to in an explicit
:class:`.PrimaryKeyConstraint` for that table.  This behavior now
matches that of when the :class:`.Column` itself has the
:paramref:`.Column.primary_key` flag set to ``True``, which is
intended to be an exactly equivalent case.
fixes #3023
2014-06-20 18:03:28 -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