Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic/hooks/database_psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def _add_defaults(parsed_host, parsed_hostaddr, parsed_port, parsed_database):


def wrapper_psycopg_as_string(wrapped, instance, args, kwargs):
def _bind_params(context, *args, **kwargs):
def _bind_params(context=None, *args, **kwargs):
return context, args, kwargs

context, _args, _kwargs = _bind_params(*args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions tests/datastore_psycopg/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from testing_support.fixture.event_loop import event_loop as loop
from testing_support.fixtures import collector_agent_registration_fixture, collector_available_fixture

from newrelic.common.package_version_utils import get_package_version_tuple

_default_settings = {
"package_reporting.enabled": False, # Turn off package reporting for testing as it causes slow downs.
"transaction_tracer.explain_threshold": 0.0,
Expand All @@ -36,6 +38,7 @@

DB_MULTIPLE_SETTINGS = postgresql_settings()
DB_SETTINGS = DB_MULTIPLE_SETTINGS[0]
PSYCOPG_VERSION = get_package_version_tuple("psycopg")


@pytest.fixture(scope="session", params=["sync", "async"])
Expand Down
12 changes: 12 additions & 0 deletions tests/datastore_psycopg/test_as_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
from conftest import PSYCOPG_VERSION

try:
from psycopg import sql
except ImportError:
Expand Down Expand Up @@ -109,3 +112,12 @@ def test_as_string_10(connection):
)
result = q2.as_string(connection)
assert result == 'insert into table ("foo", "bar", "baz") values (%(foo)s, %(bar)s, %(baz)s)'


@pytest.mark.skipif(PSYCOPG_VERSION < (3, 2, 0), reason="This signature was changed in psycopg 3.2.0")
@background_task()
def test_as_string_11(connection):
ident = sql.Identifier("foo")
# No context provided to as_string(), should not raise an error
result = ident.as_string()
assert result == '"foo"'
Loading