3535
3636# Increment this PATCH version before using `charmcraft publish-lib` or reset
3737# to 0 if you are raising the major API version
38- LIBPATCH = 48
38+ LIBPATCH = 50
3939
4040# Groups to distinguish HBA access
4141ACCESS_GROUP_IDENTITY = "identity_access"
@@ -435,6 +435,7 @@ def enable_disable_extensions(
435435 for extension , enable in extensions .items ():
436436 ordered_extensions [extension ] = enable
437437
438+ self ._configure_pgaudit (False )
438439 # Enable/disabled the extension in each database.
439440 for database in databases :
440441 with self ._connect_to_database (
@@ -446,14 +447,14 @@ def enable_disable_extensions(
446447 if enable
447448 else f"DROP EXTENSION IF EXISTS { extension } ;"
448449 )
449- self ._configure_pgaudit (ordered_extensions .get ("pgaudit" , False ))
450450 except psycopg2 .errors .UniqueViolation :
451451 pass
452452 except psycopg2 .errors .DependentObjectsStillExist :
453453 raise
454454 except psycopg2 .Error as e :
455455 raise PostgreSQLEnableDisableExtensionError () from e
456456 finally :
457+ self ._configure_pgaudit (ordered_extensions .get ("pgaudit" , False ))
457458 if connection is not None :
458459 connection .close ()
459460
@@ -626,6 +627,7 @@ def list_access_groups(self) -> Set[str]:
626627 Returns:
627628 List of PostgreSQL database access groups.
628629 """
630+ connection = None
629631 try :
630632 with self ._connect_to_database () as connection , connection .cursor () as cursor :
631633 cursor .execute (
@@ -646,6 +648,7 @@ def list_users(self) -> Set[str]:
646648 Returns:
647649 List of PostgreSQL database users.
648650 """
651+ connection = None
649652 try :
650653 with self ._connect_to_database () as connection , connection .cursor () as cursor :
651654 cursor .execute ("SELECT usename FROM pg_catalog.pg_user;" )
@@ -664,6 +667,7 @@ def list_users_from_relation(self) -> Set[str]:
664667 Returns:
665668 List of PostgreSQL database users.
666669 """
670+ connection = None
667671 try :
668672 with self ._connect_to_database () as connection , connection .cursor () as cursor :
669673 cursor .execute (
0 commit comments