Skip to content

Commit 668bcae

Browse files
committed
fix(pgadmin): align kuttl asserts with python3.12 and fix CLI delete_adhoc_servers guard
Updates the four user-management assert scripts to the python3.12 site-packages path and replaces the broken app.name.endswith('-cli') guard with hasattr(app, 'login_manager') to stop setup.py crashing in pgAdmin 9.15. Upstream: pgadmin-org/pgadmin4#9987
1 parent 4ac7832 commit 668bcae

5 files changed

Lines changed: 20 additions & 14 deletions

File tree

components/image-pgadmin/Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,18 @@ microdnf install -y --nodocs \
137137
&& update-alternatives --install /usr/bin/python3 python3 "/usr/bin/python${PYTHON_VERSION}" 1 \
138138
&& update-alternatives --set python3 "/usr/bin/python${PYTHON_VERSION}"
139139

140-
# The operator invokes pgAdmin's setup.py CLI (add-user, update-user, load-servers,
141-
# setup-db) against the same install that gunicorn is serving. When setup.py runs
142-
# as a CLI, pgAdmin's Flask app.name ends with "-cli" and delete_adhoc_servers()
143-
# wipes servers users registered through the web UI. Gate that call so it only
144-
# runs for non-CLI invocations.
145-
RUN sed -i "s/delete_adhoc_servers()/if not app.name.endswith('-cli'): delete_adhoc_servers()/g" \
140+
# Skip delete_adhoc_servers() when pgAdmin is invoked via its CLI entrypoints
141+
# (setup.py add-user / update-user / load-servers / setup-db). The CLI path
142+
# calls create_app() WITHOUT initializing login_manager, so as of pgAdmin 9.15
143+
# delete_adhoc_servers() crashes with:
144+
# AttributeError: 'PgAdmin' object has no attribute 'login_manager'
145+
# (via current_user.is_authenticated -> _get_user -> current_app.login_manager).
146+
# An earlier `app.name.endswith('-cli')` guard is unreliable because Flask
147+
# derives app.name from the import name ("pgadmin"), not from the app_name arg
148+
# create_app receives. Gate on login_manager's actual presence instead:
149+
# True only for the gunicorn-served web app, False for every CLI invocation.
150+
# Tracked upstream: https://github.com/pgadmin-org/pgadmin4/issues/9987
151+
RUN sed -i "s/delete_adhoc_servers()/(hasattr(app, 'login_manager') and delete_adhoc_servers())/g" \
146152
/usr/local/lib/python${PYTHON_VERSION}/site-packages/pgadmin4/pgadmin/__init__.py
147153

148154
# config_local.py should be colocated with config.py

testing/kuttl/e2e/standalone-pgadmin-user-management/01-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ commands:
66
pod_name=$(kubectl get pod -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
77
secret_name=$(kubectl get secret -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
88
9-
# /usr/local/lib/python3.11/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10-
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.11/site-packages/pgadmin4/setup.py get-users --json")
9+
# /usr/local/lib/python3.12/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10+
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.12/site-packages/pgadmin4/setup.py get-users --json")
1111
1212
bob_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="bob@example.com") | .role')
1313
dave_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="dave@example.com") | .role')

testing/kuttl/e2e/standalone-pgadmin-user-management/03-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ commands:
66
pod_name=$(kubectl get pod -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
77
secret_name=$(kubectl get secret -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
88
9-
# /usr/local/lib/python3.11/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10-
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.11/site-packages/pgadmin4/setup.py get-users --json")
9+
# /usr/local/lib/python3.12/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10+
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.12/site-packages/pgadmin4/setup.py get-users --json")
1111
1212
bob_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="bob@example.com") | .role')
1313
dave_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="dave@example.com") | .role')

testing/kuttl/e2e/standalone-pgadmin-user-management/05-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ commands:
66
pod_name=$(kubectl get pod -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
77
secret_name=$(kubectl get secret -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
88
9-
# /usr/local/lib/python3.11/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10-
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.11/site-packages/pgadmin4/setup.py get-users --json")
9+
# /usr/local/lib/python3.12/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10+
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.12/site-packages/pgadmin4/setup.py get-users --json")
1111
1212
bob_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="bob@example.com") | .role')
1313
dave_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="dave@example.com") | .role')

testing/kuttl/e2e/standalone-pgadmin-user-management/07-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ commands:
66
pod_name=$(kubectl get pod -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
77
secret_name=$(kubectl get secret -n "${NAMESPACE}" -l postgres-operator.crunchydata.com/pgadmin=pgadmin -o name)
88
9-
# /usr/local/lib/python3.11/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10-
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.11/site-packages/pgadmin4/setup.py get-users --json")
9+
# /usr/local/lib/python3.12/site-packages/pgadmin4 allows for various Python versions to be referenced in testing
10+
users_in_pgadmin=$(kubectl exec -n "${NAMESPACE}" "${pod_name}" -- bash -c "python3 /usr/local/lib/python3.12/site-packages/pgadmin4/setup.py get-users --json")
1111
1212
bob_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="bob@example.com") | .role')
1313
dave_role=$(printf '%s\n' $users_in_pgadmin | jq -r '.[] | select(.username=="dave@example.com") | .role')

0 commit comments

Comments
 (0)