diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-29 17:31:12 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-30 14:01:52 -0400 |
commit | ae14861a3197513db5f5a4e3991243482053a46c (patch) | |
tree | 9d6544fe694e3ffe2304013d43f9b17c6a1b99ea /lib/sqlalchemy/sql/functions.py | |
parent | a10a4ea1248902349d789de7f5470bb8e437a584 (diff) | |
download | sqlalchemy-ae14861a3197513db5f5a4e3991243482053a46c.tar.gz |
Make the GenericFunction registry fully case insensitive
Registered function names based on :class:`.GenericFunction` are now
retrieved in a case-insensitive fashion in all cases, removing the
deprecation logic from 1.3 which temporarily allowed multiple
:class:`.GenericFunction` objects to exist with differing cases. A
:class:`.GenericFunction` that replaces another on the same name whether or
not it's case sensitive emits a warning before replacing the object.
Fixes: #4649
Change-Id: I265ae19833132db07ed5b5ae40c4d24f659b1ab3
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 64 |
1 files changed, 6 insertions, 58 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index d3775ea6b..feb4fdb90 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -37,13 +37,6 @@ from .. import util _registry = util.defaultdict(dict) -_case_sensitive_registry = util.defaultdict( - lambda: util.defaultdict(dict) -) -_CASE_SENSITIVE = util.symbol( - name="case_sensitive_function", - doc="Symbol to mark the functions that are switched into case-sensitive " - "mode.") def register_function(identifier, fn, package="_default"): @@ -56,57 +49,15 @@ def register_function(identifier, fn, package="_default"): """ reg = _registry[package] - case_sensitive_reg = _case_sensitive_registry[package] raw_identifier = identifier identifier = identifier.lower() - # Check if a function with the same lowercase identifier is registered. - if identifier in reg and reg[identifier] is not _CASE_SENSITIVE: - if raw_identifier in case_sensitive_reg[identifier]: - util.warn( - "The GenericFunction '{}' is already registered and " - "is going to be overriden.".format(identifier)) - reg[identifier] = fn - else: - # If a function with the same lowercase identifier is registered, - # then these 2 functions are considered as case-sensitive. - # Note: This case should raise an error in a later release. - util.warn_deprecated( - "GenericFunction '{}' is already registered with " - "different letter case, so the previously registered function " - "'{}' is switched into case-sensitive mode. " - "GenericFunction objects will be fully case-insensitive in a " - "future release.".format( - raw_identifier, - list(case_sensitive_reg[identifier].keys())[0], - )) - reg[identifier] = _CASE_SENSITIVE - - # Check if a function with different letter case identifier is registered. - elif identifier in case_sensitive_reg: - # Note: This case will be removed in a later release. - if ( - raw_identifier not in case_sensitive_reg[identifier] - ): - util.warn_deprecated( - "GenericFunction(s) '{}' are already registered with " - "different letter cases and might interact with '{}'. " - "GenericFunction objects will be fully case-insensitive in a " - "future release.".format( - sorted(case_sensitive_reg[identifier].keys()), - raw_identifier)) - - else: - util.warn( - "The GenericFunction '{}' is already registered and " - "is going to be overriden.".format(raw_identifier)) - - # Register by default - else: - reg[identifier] = fn - - # Always register in case-sensitive registry - case_sensitive_reg[identifier][raw_identifier] = fn + # Check if a function with the same identifier is registered. + if identifier in reg: + util.warn( + "The GenericFunction '{}' is already registered and " + "is going to be overriden.".format(identifier)) + reg[identifier] = fn class FunctionElement(Executable, ColumnElement, FromClause): @@ -511,9 +462,6 @@ class _FunctionGenerator(object): if package is not None: func = _registry[package].get(fname.lower()) - if func is _CASE_SENSITIVE: - case_sensitive_reg = _case_sensitive_registry[package] - func = case_sensitive_reg.get(fname.lower()).get(fname) if func is not None: return func(*c, **o) |