diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 7cc1c99..2b2091a 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -219,11 +219,6 @@ class AlterError(Exception): pass -class FunctionAlreadyRegistered(Exception): - "A function with this name and arity was already registered" - pass - - class NoObviousTable(Exception): "Could not tell which table this operation refers to" pass @@ -414,9 +409,7 @@ class Database: fn_name = name or fn.__name__ arity = len(inspect.signature(fn).parameters) if not replace and (fn_name, arity) in self._registered_functions: - raise FunctionAlreadyRegistered( - f'Already registered function with name "{fn_name}" and identical arity' - ) + return fn kwargs = {} registered = False if deterministic: diff --git a/tests/test_register_function.py b/tests/test_register_function.py index 5b92631..e2591f4 100644 --- a/tests/test_register_function.py +++ b/tests/test_register_function.py @@ -3,7 +3,6 @@ import pytest import sys from unittest.mock import MagicMock, call from sqlite_utils.utils import sqlite3 -from sqlite_utils.db import FunctionAlreadyRegistered def test_register_function(fresh_db): @@ -85,12 +84,10 @@ def test_register_function_replace(fresh_db): assert "one" == fresh_db.execute("select one()").fetchone()[0] - # This will fail to replace the function: - with pytest.raises(FunctionAlreadyRegistered): - - @fresh_db.register_function() - def one(): # noqa - return "two" + # This will silently fail to replaec the function + @fresh_db.register_function() + def one(): # noqa + return "two" assert "one" == fresh_db.execute("select one()").fetchone()[0] @@ -100,12 +97,3 @@ def test_register_function_replace(fresh_db): return "two" assert "two" == fresh_db.execute("select one()").fetchone()[0] - - -def test_register_function_duplicate(fresh_db): - def to_lower(s): - return s.lower() - - fresh_db.register_function(to_lower) - with pytest.raises(FunctionAlreadyRegistered): - fresh_db.register_function(to_lower)