diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2019-10-14 19:22:47 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-10-14 19:22:47 +0000 |
| commit | 567ee8d6a90a150e5079fc6d1cdad2734172e2e7 (patch) | |
| tree | 9a9ececeadd57497700169761f75c08b367fd840 /lib/sqlalchemy/sql/elements.py | |
| parent | ea8856e8b0fc2ca41a0e410161a25d70d919721c (diff) | |
| parent | 41dc71ad2fc1963a44e5f308f53aed6b8d7d662a (diff) | |
| download | sqlalchemy-567ee8d6a90a150e5079fc6d1cdad2734172e2e7.tar.gz | |
Merge "Use separate label generator for column_label naming convention"
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index b6462b334..78c434cff 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -4263,7 +4263,11 @@ class ColumnClause(roles.LabeledColumnExprRole, Immutable, ColumnElement): def _render_label_in_columns_clause(self): return self.table is not None - def _gen_label(self, name): + @property + def _ddl_label(self): + return self._gen_label(self.name, dedupe_on_key=False) + + def _gen_label(self, name, dedupe_on_key=True): t = self.table if self.is_literal: @@ -4287,21 +4291,22 @@ class ColumnClause(roles.LabeledColumnExprRole, Immutable, ColumnElement): assert not isinstance(label, quoted_name) label = quoted_name(label, t.name.quote) - # ensure the label name doesn't conflict with that - # of an existing column. note that this implies that any - # Column must **not** set up its _label before its parent table - # has all of its other Column objects set up. There are several - # tables in the test suite which will fail otherwise; example: - # table "owner" has columns "name" and "owner_name". Therefore - # column owner.name cannot use the label "owner_name", it has - # to be "owner_name_1". - if label in t.c: - _label = label - counter = 1 - while _label in t.c: - _label = label + "_" + str(counter) - counter += 1 - label = _label + if dedupe_on_key: + # ensure the label name doesn't conflict with that of an + # existing column. note that this implies that any Column + # must **not** set up its _label before its parent table has + # all of its other Column objects set up. There are several + # tables in the test suite which will fail otherwise; example: + # table "owner" has columns "name" and "owner_name". Therefore + # column owner.name cannot use the label "owner_name", it has + # to be "owner_name_1". + if label in t.c: + _label = label + counter = 1 + while _label in t.c: + _label = label + "_" + str(counter) + counter += 1 + label = _label return coercions.expect(roles.TruncatedLabelRole, label) |
