Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9620a5a

Browse filesBrowse files
authored
fix(GoogleCloudPlatform#10940): Replacing depracated before_first_request decorator (GoogleCloudPlatform#11007)
1 parent 03db77b commit 9620a5a
Copy full SHA for 9620a5a

File tree

Expand file treeCollapse file tree

4 files changed

+15
-11
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-11
lines changed

‎cloud-sql/mysql/sqlalchemy/app.py

Copy file name to clipboardExpand all lines: cloud-sql/mysql/sqlalchemy/app.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
8181
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
8282
# App Engine may wish to skip this lazy instantiation and connect as soon
8383
# as the function is loaded. This is primarily to help testing.
84-
@app.before_first_request
84+
@app.before_request
8585
def init_db() -> sqlalchemy.engine.base.Engine:
8686
"""Initiates connection to database and its' structure."""
8787
global db
88-
db = init_connection_pool()
89-
migrate_db(db)
88+
if db is None:
89+
db = init_connection_pool()
90+
migrate_db(db)
9091

9192

9293
@app.route("/", methods=["GET"])

‎cloud-sql/postgres/sqlalchemy/app.py

Copy file name to clipboardExpand all lines: cloud-sql/postgres/sqlalchemy/app.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
8181
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
8282
# App Engine may wish to skip this lazy instantiation and connect as soon
8383
# as the function is loaded. This is primarily to help testing.
84-
@app.before_first_request
84+
@app.before_request
8585
def init_db() -> sqlalchemy.engine.base.Engine:
8686
"""Initiates connection to database and its structure."""
8787
global db
88-
db = init_connection_pool()
89-
migrate_db(db)
88+
if db is None:
89+
db = init_connection_pool()
90+
migrate_db(db)
9091

9192

9293
@app.route("/", methods=["GET"])

‎cloud-sql/sql-server/sqlalchemy/app.py

Copy file name to clipboardExpand all lines: cloud-sql/sql-server/sqlalchemy/app.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ def migrate_db(db: sqlalchemy.engine.base.Engine) -> None:
7373
# init_db lazily instantiates a database connection pool. Users of Cloud Run or
7474
# App Engine may wish to skip this lazy instantiation and connect as soon
7575
# as the function is loaded. This is primarily to help testing.
76-
@app.before_first_request
76+
@app.before_request
7777
def init_db() -> sqlalchemy.engine.base.Engine:
7878
global db
79-
db = init_connection_pool()
80-
migrate_db(db)
79+
if db is None:
80+
db = init_connection_pool()
81+
migrate_db(db)
8182

8283

8384
@app.route("/", methods=["GET"])

‎compute/managed-instances/demo/app.py

Copy file name to clipboardExpand all lines: compute/managed-instances/demo/app.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
_cpu_burner = None
4040

4141

42-
@app.before_first_request
42+
@app.before_request
4343
def init():
4444
"""Initialize the application."""
4545
global _cpu_burner
46-
_cpu_burner = CpuBurner()
46+
if _cpu_burner is None:
47+
_cpu_burner = CpuBurner()
4748

4849

4950
@app.route("/")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.