Package: python-oauth2client
Followup-For: Bug #1063782
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu noble ubuntu-patch
Control: tags -1 patch

Dear Maintainer,

Flask 3.0 dropped support for _app_ctx_stack and _request_ctx_stack.
Those attributes were deprecated since Flask 2.2.

In Ubuntu, the attached patch was applied to achieve the following:

  * Replace use of flask._app_ctx_stack (dropped from flask 3) by flask.g to
    fix FTBFS. (LP: #2052771)
     - debian/patches/flask3-use-g-instead-of-app_ctx_stack.patch


Thanks for considering the patch.


-- System Information:
Debian Release: trixie/sid
  APT prefers mantic-updates
  APT policy: (500, 'mantic-updates'), (500, 'mantic-security'), (500, 
'mantic'), (100, 'mantic-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.1.0-16-generic (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru 
python-oauth2client-4.1.3/debian/patches/flask3-use-g-instead-of-app_ctx_stack.patch
 
python-oauth2client-4.1.3/debian/patches/flask3-use-g-instead-of-app_ctx_stack.patch
--- 
python-oauth2client-4.1.3/debian/patches/flask3-use-g-instead-of-app_ctx_stack.patch
        1970-01-01 01:00:00.000000000 +0100
+++ 
python-oauth2client-4.1.3/debian/patches/flask3-use-g-instead-of-app_ctx_stack.patch
        2024-02-16 10:51:37.000000000 +0100
@@ -0,0 +1,43 @@
+Description: Use flask.g instead of flask._app_ctx_stack
+ In flask 2.2, _app_ctx_stack and _request_ctx_stack got deprecated in favor of
+ using flask.g. The compatibility layer was dropped from flask 3, which now 
raises:
+   E ImportError: cannot import name '_app_ctx_stack' from 'flask'
+ Replaced by the use of flask.g as mentioned in the documentation.
+ .
+ The patch is not meant for upstream inclusion since the project upstream is
+ deprecated (in favor of python-google-auth) and the repository is read only.
+Author: Olivier Gayot <olivier.ga...@canonical.com>
+Bug-Ubuntu: https://launchpad.net/bugs/2052771
+Bug-Debian: https://bugs.debian.org/1063782
+Forwarded: not-needed
+Last-Update: 2024-02-16
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/oauth2client/contrib/flask_util.py
++++ b/oauth2client/contrib/flask_util.py
+@@ -170,8 +170,8 @@
+ 
+ try:
+     from flask import Blueprint
+-    from flask import _app_ctx_stack
+     from flask import current_app
++    from flask import g as flask_g
+     from flask import redirect
+     from flask import request
+     from flask import session
+@@ -434,12 +434,10 @@
+     @property
+     def credentials(self):
+         """The credentials for the current user or None if unavailable."""
+-        ctx = _app_ctx_stack.top
++        if not hasattr(flask_g, _CREDENTIALS_KEY):
++            flask_g.google_oauth2_credentials = self.storage.get()
+ 
+-        if not hasattr(ctx, _CREDENTIALS_KEY):
+-            ctx.google_oauth2_credentials = self.storage.get()
+-
+-        return ctx.google_oauth2_credentials
++        return flask_g.google_oauth2_credentials
+ 
+     def has_credentials(self):
+         """Returns True if there are valid credentials for the current 
user."""
diff -Nru python-oauth2client-4.1.3/debian/patches/series 
python-oauth2client-4.1.3/debian/patches/series
--- python-oauth2client-4.1.3/debian/patches/series     2023-08-17 
18:22:35.000000000 +0200
+++ python-oauth2client-4.1.3/debian/patches/series     2024-02-16 
10:51:37.000000000 +0100
@@ -1,3 +1,5 @@
+flask3-use-g-instead-of-app_ctx_stack.patch
 skip-network-doing-unit-test.patch
 remove-broken-tests.patch
 fix-hmac.new-call-in-py3.8.patch

Reply via email to