Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
26c1ad71
Unverified
Commit
26c1ad71
authored
2 years ago
by
David Robertson
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use `Concatenate` to annotate `do_execute` (#12666)
parent
0ce22019
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/12666.misc
+1
-0
1 addition, 0 deletions
changelog.d/12666.misc
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
synapse/storage/database.py
+14
-5
14 additions, 5 deletions
synapse/storage/database.py
with
16 additions
and
6 deletions
changelog.d/12666.misc
0 → 100644
+
1
−
0
View file @
26c1ad71
Use `Concatenate` to better annotate `_do_execute`.
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
26c1ad71
...
@@ -142,7 +142,7 @@ netaddr = ">=0.7.18"
...
@@ -142,7 +142,7 @@ netaddr = ">=0.7.18"
# add a lower bound to the Jinja2 dependency.
# add a lower bound to the Jinja2 dependency.
Jinja2
=
">
=
3.0
"
Jinja2
=
">
=
3.0
"
bleach
=
">
=
1.4
.
3
"
bleach
=
">
=
1.4
.
3
"
# We use `ParamSpec`, which w
as
added in `typing-extensions` 3.10.0.0.
# We use `ParamSpec`
and `Concatenate`
, which w
ere
added in `typing-extensions` 3.10.0.0.
typing-extensions
=
">
=
3.10
.
0
"
typing-extensions
=
">
=
3.10
.
0
"
# We enforce that we have a `cryptography` version that bundles an `openssl`
# We enforce that we have a `cryptography` version that bundles an `openssl`
# with the latest security patches.
# with the latest security patches.
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/database.py
+
14
−
5
View file @
26c1ad71
...
@@ -38,7 +38,7 @@ from typing import (
...
@@ -38,7 +38,7 @@ from typing import (
import
attr
import
attr
from
prometheus_client
import
Histogram
from
prometheus_client
import
Histogram
from
typing_extensions
import
Literal
from
typing_extensions
import
Concatenate
,
Literal
,
ParamSpec
from
twisted.enterprise
import
adbapi
from
twisted.enterprise
import
adbapi
...
@@ -194,7 +194,7 @@ class LoggingDatabaseConnection:
...
@@ -194,7 +194,7 @@ class LoggingDatabaseConnection:
# The type of entry which goes on our after_callbacks and exception_callbacks lists.
# The type of entry which goes on our after_callbacks and exception_callbacks lists.
_CallbackListEntry
=
Tuple
[
Callable
[...,
object
],
Iterable
[
Any
],
Dict
[
str
,
Any
]]
_CallbackListEntry
=
Tuple
[
Callable
[...,
object
],
Iterable
[
Any
],
Dict
[
str
,
Any
]]
P
=
ParamSpec
(
"
P
"
)
R
=
TypeVar
(
"
R
"
)
R
=
TypeVar
(
"
R
"
)
...
@@ -339,7 +339,13 @@ class LoggingTransaction:
...
@@ -339,7 +339,13 @@ class LoggingTransaction:
"
Strip newlines out of SQL so that the loggers in the DB are on one line
"
"
Strip newlines out of SQL so that the loggers in the DB are on one line
"
return
"
"
.
join
(
line
.
strip
()
for
line
in
sql
.
splitlines
()
if
line
.
strip
())
return
"
"
.
join
(
line
.
strip
()
for
line
in
sql
.
splitlines
()
if
line
.
strip
())
def
_do_execute
(
self
,
func
:
Callable
[...,
R
],
sql
:
str
,
*
args
:
Any
)
->
R
:
def
_do_execute
(
self
,
func
:
Callable
[
Concatenate
[
str
,
P
],
R
],
sql
:
str
,
*
args
:
P
.
args
,
**
kwargs
:
P
.
kwargs
,
)
->
R
:
sql
=
self
.
_make_sql_one_line
(
sql
)
sql
=
self
.
_make_sql_one_line
(
sql
)
# TODO(paul): Maybe use 'info' and 'debug' for values?
# TODO(paul): Maybe use 'info' and 'debug' for values?
...
@@ -348,7 +354,10 @@ class LoggingTransaction:
...
@@ -348,7 +354,10 @@ class LoggingTransaction:
sql
=
self
.
database_engine
.
convert_param_style
(
sql
)
sql
=
self
.
database_engine
.
convert_param_style
(
sql
)
if
args
:
if
args
:
try
:
try
:
sql_logger
.
debug
(
"
[SQL values] {%s} %r
"
,
self
.
name
,
args
[
0
])
# The type-ignore should be redundant once mypy releases a version with
# https://github.com/python/mypy/pull/12668. (`args` might be empty,
# (but we'll catch the index error if so.)
sql_logger
.
debug
(
"
[SQL values] {%s} %r
"
,
self
.
name
,
args
[
0
])
# type: ignore[index]
except
Exception
:
except
Exception
:
# Don't let logging failures stop SQL from working
# Don't let logging failures stop SQL from working
pass
pass
...
@@ -363,7 +372,7 @@ class LoggingTransaction:
...
@@ -363,7 +372,7 @@ class LoggingTransaction:
opentracing
.
tags
.
DATABASE_STATEMENT
:
sql
,
opentracing
.
tags
.
DATABASE_STATEMENT
:
sql
,
},
},
):
):
return
func
(
sql
,
*
args
)
return
func
(
sql
,
*
args
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
as
e
:
sql_logger
.
debug
(
"
[SQL FAIL] {%s} %s
"
,
self
.
name
,
e
)
sql_logger
.
debug
(
"
[SQL FAIL] {%s} %s
"
,
self
.
name
,
e
)
raise
raise
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment