details:   https://code.tryton.org/tryton/commit/933d88b25860
branch:    default
user:      Nicolas Évrard <[email protected]>
date:      Tue Oct 28 10:57:07 2025 +0100
description:
        Add a clear cache method to the Database

        ExtensionTestCase uses this new method to clear all the caches of the 
Database.
diffstat:

 trytond/CHANGELOG                              |   1 +
 trytond/doc/ref/backend.rst                    |   4 ++++
 trytond/trytond/backend/database.py            |   4 ++++
 trytond/trytond/backend/postgresql/database.py |  15 +++++++++++++--
 trytond/trytond/backend/sqlite/database.py     |   5 +++++
 trytond/trytond/tests/test_tryton.py           |   8 ++------
 6 files changed, 29 insertions(+), 8 deletions(-)

diffs (103 lines):

diff -r 488a1008680c -r 933d88b25860 trytond/CHANGELOG
--- a/trytond/CHANGELOG Thu May 22 18:24:57 2025 +0200
+++ b/trytond/CHANGELOG Tue Oct 28 10:57:07 2025 +0100
@@ -1,3 +1,4 @@
+* Add a clear cache method to the Database
 * Add sequence_reorder to model order
 * Remove has_window_functions from Database
 * Set minimal supported version of SQLite to 3.30.0
diff -r 488a1008680c -r 933d88b25860 trytond/doc/ref/backend.rst
--- a/trytond/doc/ref/backend.rst       Thu May 22 18:24:57 2025 +0200
+++ b/trytond/doc/ref/backend.rst       Tue Oct 28 10:57:07 2025 +0100
@@ -50,6 +50,10 @@
 
    Drop the named database using the connection.
 
+.. classmethod:: Database.clear_cache()
+
+   Clear the cached values regarding the database properties.
+
 .. method:: Database.list([hostname])
 
    Return a list of Tryton database names.
diff -r 488a1008680c -r 933d88b25860 trytond/trytond/backend/database.py
--- a/trytond/trytond/backend/database.py       Thu May 22 18:24:57 2025 +0200
+++ b/trytond/trytond/backend/database.py       Tue Oct 28 10:57:07 2025 +0100
@@ -45,6 +45,10 @@
     def drop(cls, connection, database_name):
         raise NotImplementedError
 
+    @classmethod
+    def clear_cache(cls):
+        pass
+
     def list(self, hostname=None):
         raise NotImplementedError
 
diff -r 488a1008680c -r 933d88b25860 
trytond/trytond/backend/postgresql/database.py
--- a/trytond/trytond/backend/postgresql/database.py    Thu May 22 18:24:57 
2025 +0200
+++ b/trytond/trytond/backend/postgresql/database.py    Tue Oct 28 10:57:07 
2025 +0100
@@ -330,9 +330,20 @@
         cursor = connection.cursor()
         cursor.execute(SQL("DROP DATABASE {}")
             .format(Identifier(database_name)))
+        cls.clear_cache()
+
+    @classmethod
+    def clear_cache(cls):
         cls._list_cache.clear()
-        cls._has_proc.pop(database_name, None)
-        cls._search_full_text_languages.pop(database_name, None)
+        cls._list_cache_timestamp.clear()
+        cls._search_path = None
+        cls._current_user = None
+        cls._has_returning = None
+        cls._has_insert_on_conflict = None
+        cls._has_select_for_skip_locked = None
+        cls._has_proc.clear()
+        cls._extensions.clear()
+        cls._search_full_text_languages.clear()
 
     def get_version(self, connection):
         version = connection.server_version
diff -r 488a1008680c -r 933d88b25860 trytond/trytond/backend/sqlite/database.py
--- a/trytond/trytond/backend/sqlite/database.py        Thu May 22 18:24:57 
2025 +0200
+++ b/trytond/trytond/backend/sqlite/database.py        Tue Oct 28 10:57:07 
2025 +0100
@@ -613,7 +613,12 @@
                     os.remove(file + suffix)
                 except FileNotFoundError:
                     pass
+        cls.clear_cache()
+
+    @classmethod
+    def clear_cache(cls):
         cls._list_cache.clear()
+        cls._list_cache_timestamp.clear()
 
     def list(self, hostname=None):
         now = time.time()
diff -r 488a1008680c -r 933d88b25860 trytond/trytond/tests/test_tryton.py
--- a/trytond/trytond/tests/test_tryton.py      Thu May 22 18:24:57 2025 +0200
+++ b/trytond/trytond/tests/test_tryton.py      Tue Oct 28 10:57:07 2025 +0100
@@ -1265,7 +1265,7 @@
         cursor = connection.cursor()
         cursor.execute('CREATE EXTENSION "%s"' % cls.extension)
         connection.commit()
-        cls._clear_cache()
+        backend.Database.clear_cache()
 
     @classmethod
     @with_transaction()
@@ -1274,11 +1274,7 @@
         cursor = connection.cursor()
         cursor.execute('DROP EXTENSION "%s"' % cls.extension)
         connection.commit()
-        cls._clear_cache()
-
-    @classmethod
-    def _clear_cache(cls):
-        backend.Database._has_proc.clear()
+        backend.Database.clear_cache()
 
 
 def drop_db(name=DB_NAME):

Reply via email to