]> git.ipfire.org Git - thirdparty/psycopg.git/log
thirdparty/psycopg.git
3 years agofix: shorter traceback on COPY error
Daniele Varrazzo [Thu, 19 May 2022 23:58:01 +0000 (01:58 +0200)] 
fix: shorter traceback on COPY error

3 years agofix: raise a shorter trackeback on interrupted notify connection
Daniele Varrazzo [Wed, 18 May 2022 20:45:48 +0000 (22:45 +0200)] 
fix: raise a shorter trackeback on interrupted notify connection

3 years agoTest: fix mypy 0.941 run
Daniele Varrazzo [Thu, 19 May 2022 21:41:26 +0000 (23:41 +0200)] 
Test: fix mypy 0.941 run

This seems a mypy shortcoming fixed in 0.950 as the CI didn't complain.
The row factory definition was exotic but arguably correct. Not worth
bumping up the min version for it anyway.

3 years agoMerge remote-tracking branch 'dlax/row-covariant'
Daniele Varrazzo [Thu, 19 May 2022 21:07:19 +0000 (23:07 +0200)] 
Merge remote-tracking branch 'dlax/row-covariant'

3 years agofix: only use covariant Row type variable 306/head
Denis Laxalde [Mon, 16 May 2022 17:16:53 +0000 (19:16 +0200)] 
fix: only use covariant Row type variable

The real variance of Row type variable is covariant, per definition of
RowMaker (RowMaker[B] is a subtype of RowMaker[A] if B is a subtype of
A; similar to the Box type in [mypy documentation][]).

By dropping the Row type variable from Cursor argument in RowFactory, we
are now able to only use the covariant Row variable (previously Row_co,
now Row). Indeed, RowFactory does not actually depend on Cursor on being
parametrized on Row; rather it's the other way around (Cursor's Row type
variable comes from its row factory).

[mypy documentation]: https://mypy.readthedocs.io/en/latest/generics.html#variance-of-generic-types

3 years agofix: use a more generic connection type in {Client,Server}Cursor
Denis Laxalde [Sun, 15 May 2022 12:28:36 +0000 (14:28 +0200)] 
fix: use a more generic connection type in {Client,Server}Cursor

This makes them similar to plain Cursor class, i.e. being parametrized
on sync or async connection type, not the row type (which is handled
through the second type variable).

3 years agorefactor: streamline 'type: ignore' in *Cursor.stream()
Denis Laxalde [Sun, 15 May 2022 09:13:38 +0000 (11:13 +0200)] 
refactor: streamline 'type: ignore' in *Cursor.stream()

Make AsyncCursor code similar to Cursor one.

3 years agofix: sync pipeline after tpc_prepare()
Denis Laxalde [Tue, 10 May 2022 19:24:12 +0000 (21:24 +0200)] 
fix: sync pipeline after tpc_prepare()

This is to get the NotSupported raised directly when calling
tpc_prepare() as expected in test_tpc_disabled().

3 years agostyle: import PipelineStatus members in the module like for other pq enums
Daniele Varrazzo [Tue, 17 May 2022 19:24:45 +0000 (21:24 +0200)] 
style: import PipelineStatus members in the module like for other pq enums

3 years agoperf: micro optimise attribute access to PollingStatus
Daniele Varrazzo [Tue, 17 May 2022 19:23:18 +0000 (21:23 +0200)] 
perf: micro optimise attribute access to PollingStatus

3 years agoperf: micro optimise attribute access to ConnStatus
Daniele Varrazzo [Tue, 17 May 2022 19:20:34 +0000 (21:20 +0200)] 
perf: micro optimise attribute access to ConnStatus

3 years agoperf: micro optimise attribute access to TransactionStatus
Daniele Varrazzo [Tue, 17 May 2022 19:14:51 +0000 (21:14 +0200)] 
perf: micro optimise attribute access to TransactionStatus

3 years agoperf: micro optimise attribute access to ExecStatus
Daniele Varrazzo [Tue, 17 May 2022 19:03:22 +0000 (21:03 +0200)] 
perf: micro optimise attribute access to ExecStatus

3 years agoperf: micro optimise attribute access to Format
Daniele Varrazzo [Sun, 15 May 2022 16:43:01 +0000 (18:43 +0200)] 
perf: micro optimise attribute access to Format

3 years agorefactor: while 1 -> while True
Daniele Varrazzo [Sun, 15 May 2022 15:54:14 +0000 (17:54 +0200)] 
refactor: while 1 -> while True

Brain legacy of ancient Python versions where the latter required a
global lookup.

3 years agotest: fix for Python 3.11
Daniele Varrazzo [Mon, 16 May 2022 17:40:11 +0000 (19:40 +0200)] 
test: fix for Python 3.11

The f-string expansion of str enums has changed. All the tests in the
maint-3.0 branch were already fixed; this changeset only fixes the new
ones.

3 years agoMerge branch 'fix-304'
Daniele Varrazzo [Mon, 16 May 2022 02:27:54 +0000 (04:27 +0200)] 
Merge branch 'fix-304'

3 years agofix: add C Float4 binary dumper
Daniele Varrazzo [Mon, 16 May 2022 00:41:53 +0000 (02:41 +0200)] 
fix: add C Float4 binary dumper

This should hopefully work around issue #304, at least when C is used.
When Python is used we raise an error instead.

Close #304

3 years agofix: raise an exception if the struct package is affected by issue #304
Daniele Varrazzo [Mon, 16 May 2022 00:14:56 +0000 (02:14 +0200)] 
fix: raise an exception if the struct package is affected by issue #304

Cowardly refuse to transform ones in zeros.

3 years agotest: Fix implicit f-string conversion to value
Daniele Varrazzo [Sun, 15 May 2022 17:49:14 +0000 (19:49 +0200)] 
test: Fix implicit f-string conversion to value

Behaviour changed in Python 3.11.

3 years agofix: Don't rely on f-string converting str enums in their values
Daniele Varrazzo [Sun, 15 May 2022 17:46:34 +0000 (19:46 +0200)] 
fix: Don't rely on f-string converting str enums in their values

The behaviour seems changed in Python 3.11: now f"%{PyFormat.AUTO}" is
evaluated as `%PyFormat.AUTO` instead of `%s`, for the general hilarity.

3 years agofix: fix typo: ingeger
Daniele Varrazzo [Mon, 16 May 2022 00:58:46 +0000 (02:58 +0200)] 
fix: fix typo: ingeger

3 years agochore: bump version to release 3.0.14
Daniele Varrazzo [Sun, 15 May 2022 15:46:00 +0000 (17:46 +0200)] 
chore: bump version to release 3.0.14

3 years agofix: don't barf on errors with blank sqlstate
Daniele Varrazzo [Sat, 14 May 2022 08:22:44 +0000 (10:22 +0200)] 
fix: don't barf on errors with blank sqlstate

Such messages are not entirely valid (sqlstate is documented to be
always present), however we receive them after a SHOW HELP in the
PgBouncer admin database.

The SHOW HELP actually does generate a sqlstate `00000` but the message
is somehow parsed incorrectly by the libpq, which goes on to report an
error:

    message contents do not agree with length in message type "N"

See #303. PgBouncer issue reported upstream in
https://github.com/pgbouncer/pgbouncer/issues/718

3 years agodocs: drop stray reference to psycopg3
Daniele Varrazzo [Sun, 15 May 2022 10:00:00 +0000 (12:00 +0200)] 
docs: drop stray reference to psycopg3

3 years agoMerge branch 'client-side-cursor'
Daniele Varrazzo [Sun, 15 May 2022 09:59:43 +0000 (11:59 +0200)] 
Merge branch 'client-side-cursor'

3 years agodocs: Subtly suggest to use the psycopg.sql module rather than ClientCursor 302/head
Daniele Varrazzo [Sun, 15 May 2022 09:57:22 +0000 (11:57 +0200)] 
docs: Subtly suggest to use the psycopg.sql module rather than ClientCursor

3 years agodocs: add documentation for client-side binding cursors
Daniele Varrazzo [Fri, 13 May 2022 01:13:05 +0000 (03:13 +0200)] 
docs: add documentation for client-side binding cursors

3 years agotest: test multi-statement parametric queries with client-side binding
Daniele Varrazzo [Fri, 13 May 2022 00:29:38 +0000 (02:29 +0200)] 
test: test multi-statement parametric queries with client-side binding

3 years agofix: set ClientCursor class module to psycopg
Daniele Varrazzo [Fri, 13 May 2022 00:21:10 +0000 (02:21 +0200)] 
fix: set ClientCursor class module to psycopg

3 years agofeat: add params to Cursor.copy()
Daniele Varrazzo [Thu, 12 May 2022 23:18:59 +0000 (01:18 +0200)] 
feat: add params to Cursor.copy()

3 years agotest: disable tests throwing copy to executemany in client-side cursors
Daniele Varrazzo [Thu, 12 May 2022 22:16:13 +0000 (00:16 +0200)] 
test: disable tests throwing copy to executemany in client-side cursors

The async one sometimes gets in an allocation loop. On my laptop it gets
OOM'd quickly. On Github Actions it might be the cause of test taking an
unusually long time.

3 years agofix: don't forbid all PQexec queries in client-side cursors
Daniele Varrazzo [Thu, 12 May 2022 21:47:46 +0000 (23:47 +0200)] 
fix: don't forbid all PQexec queries in client-side cursors

We can still use PQexecParams with an empty list of parameters. This has
advantages, such as the possibility of implementing stream(), and less
faffing with differences between Cursor and ClientCursor.

3 years agofeat: add ClientCursor.mogrify()
Daniele Varrazzo [Thu, 12 May 2022 14:46:28 +0000 (16:46 +0200)] 
feat: add ClientCursor.mogrify()

3 years agofeat: add ClientCursor and AsyncClientCursor classes
Daniele Varrazzo [Thu, 12 May 2022 02:25:51 +0000 (04:25 +0200)] 
feat: add ClientCursor and AsyncClientCursor classes

3 years agotest: skip testing random multirange arrays with empty last elements
Daniele Varrazzo [Sat, 14 May 2022 22:24:17 +0000 (00:24 +0200)] 
test: skip testing random multirange arrays with empty last elements

Previously we were skipping the ones with an empty first element,
because of a known shortcoming in finding the right OID. Now that we
scan the whole array to find all the elements' classes, it's the last
entry which might break dumping.

3 years agoMerge branch 'fix-301'
Daniele Varrazzo [Sat, 14 May 2022 00:02:30 +0000 (02:02 +0200)] 
Merge branch 'fix-301'

3 years agofix: allow dumping mixed types list, as long as they use the same dumper
Daniele Varrazzo [Fri, 13 May 2022 23:29:53 +0000 (01:29 +0200)] 
fix: allow dumping mixed types list, as long as they use the same dumper

Necessary to dump a mix of ipv4/ipv6 addresses, which result in the same
Postgres type, so it's a legit array.

3 years agofix: Raise DataError dumping lists of mixed types
Daniele Varrazzo [Fri, 13 May 2022 22:37:48 +0000 (00:37 +0200)] 
fix: Raise DataError dumping lists of mixed types

This requires more checking dumping lists, but the alternative is to
guard every single dumper, which is painful as well, and more brittle.

3 years agofix: raise DataError if IntDumper tries to dump another type
Daniele Varrazzo [Fri, 13 May 2022 14:54:54 +0000 (16:54 +0200)] 
fix: raise DataError if IntDumper tries to dump another type

Allow to dump int subclasses, but not other numeric type, which can lead
to truncation. As seen in #301, the Python implementation truncates; the
c implementation is reporting failing with a TypeError, but on Python
3.8 it raises a deprecation warning instead.

The condition largely happens dumping array of mixed types. However we
should probably test with array of mixed class in a more generic way.

Close #301.

3 years agotest: fix number of columns in generated faker schema
Daniele Varrazzo [Fri, 13 May 2022 22:41:14 +0000 (00:41 +0200)] 
test: fix number of columns in generated faker schema

3 years agotest: fix formats testing in number wrapper array test
Daniele Varrazzo [Fri, 13 May 2022 15:02:15 +0000 (17:02 +0200)] 
test: fix formats testing in number wrapper array test

3 years agodocs: Python enum labels -> members
Daniele Varrazzo [Thu, 12 May 2022 19:55:44 +0000 (21:55 +0200)] 
docs: Python enum labels -> members

3 years agodocs: drop docsting for AsyncPipeline.sync
Daniele Varrazzo [Thu, 12 May 2022 19:46:30 +0000 (21:46 +0200)] 
docs: drop docsting for AsyncPipeline.sync

It was out of date and, for Sync/Async objects, Async docs don't
reiterate what's on the Sync side, they only show the different
signature.

3 years agofeat: add cursor_factory parameter to `connect()`.
Daniele Varrazzo [Thu, 12 May 2022 12:48:09 +0000 (14:48 +0200)] 
feat: add cursor_factory parameter to `connect()`.

This makes easier to use ClientCursor and port more easily code running
on psycopg2 dong more DDL operations and caring less about performance.

3 years agorefactor: implement ServerCursor with a mixin rather than an helper
Daniele Varrazzo [Wed, 11 May 2022 12:38:37 +0000 (14:38 +0200)] 
refactor: implement ServerCursor with a mixin rather than an helper

This was the original intention, but some older Mypy limitation was
stopping us from doing so. Or I wasn't good enough at it.

3 years agofeat: make Cursor constructor public
Daniele Varrazzo [Wed, 4 May 2022 18:09:31 +0000 (20:09 +0200)] 
feat: make Cursor constructor public

This allows a more natural creation of cursors subclasses, without the
need of tweaking the connection's cursor_factory and allowing to pass
arbitrary init arguments to the cursor.

3 years agoMerge branch 'typed-literal'
Daniele Varrazzo [Thu, 12 May 2022 13:34:46 +0000 (15:34 +0200)] 
Merge branch 'typed-literal'

3 years agofix(sql): prefer names without space to cast builtins 264/head
Daniele Varrazzo [Sun, 20 Mar 2022 22:31:50 +0000 (23:31 +0100)] 
fix(sql): prefer names without space to cast builtins

Certain types have a regtype with spaces, such as "timestamp with time
zone". Prefer the type short name, in this case ("timestamptz").

3 years agofeat: add `Transformer.as_literal()` to convert literals to sql
Daniele Varrazzo [Sun, 20 Mar 2022 18:24:53 +0000 (19:24 +0100)] 
feat: add `Transformer.as_literal()` to convert literals to sql

This allows to keep a cache oid -> representation that will be
invalidated automatically if encoding or oid mapping changes, as well as
optimising the function in C.

3 years agofix(sql): represent array literals correctly
Daniele Varrazzo [Sun, 20 Mar 2022 18:22:47 +0000 (19:22 +0100)] 
fix(sql): represent array literals correctly

3 years agorefactor: `TypeInfo.alt_name` renamed to `regtype`
Daniele Varrazzo [Sun, 20 Mar 2022 15:21:40 +0000 (16:21 +0100)] 
refactor: `TypeInfo.alt_name` renamed to `regtype`

This has now acquired a precise meaning: it is the name of the type as
SQL snippet (it may contain invalid names, which get quoted, or a schema
name). It can be included literally in a query to make a valid cast.

The previous name wasn't documented and wasn't part of any public API so
we can probably rename it without much problem.

3 years agotest(cursor): make sure Column.name is right for invalid names too
Daniele Varrazzo [Sun, 20 Mar 2022 15:10:03 +0000 (16:10 +0100)] 
test(cursor): make sure Column.name is right for invalid names too

3 years agofix(sql): fetch correct type names in TypeInfo subclasses
Daniele Varrazzo [Sun, 20 Mar 2022 15:07:56 +0000 (16:07 +0100)] 
fix(sql): fetch correct type names in TypeInfo subclasses

Needed to fix `Literal.as_string()` of types using a `TypeInfo` subclass
to fetch info (composite, range, multirange).

3 years agofix(sql): fix `sql.Literal` with invalid type names
Daniele Varrazzo [Sun, 20 Mar 2022 15:04:54 +0000 (16:04 +0100)] 
fix(sql): fix `sql.Literal` with invalid type names

Make sure that `TypeInfo.alt_name` is always populated, even if with a
copy of `name`.

3 years agofix(composite): fix fetching composite info with invalid name or field names
Daniele Varrazzo [Sun, 20 Mar 2022 15:02:12 +0000 (16:02 +0100)] 
fix(composite): fix fetching composite info with invalid name or field names

3 years agorefactor: add _as_python_identifier() function
Daniele Varrazzo [Sun, 20 Mar 2022 14:54:44 +0000 (15:54 +0100)] 
refactor: add _as_python_identifier() function

The function takes a PostgreSQL "invalid" name (such as `a-b` or '0' or an
unicode string) and makes a valid Python name.

Currently used to make valid namedtuples from `nametuple_row()` but can
be used to make other valid Python names.

3 years agoperf: use `b"'"[0]` as const value to represent `ord("'")`
Daniele Varrazzo [Sun, 20 Mar 2022 00:44:07 +0000 (01:44 +0100)] 
perf: use `b"'"[0]` as const value to represent `ord("'")`

The value is expanded at compile time::

    >>> dis.dis('b"\'"[0]')
      1           0 LOAD_CONST               0 (39)
                  2 RETURN_VALUE

3 years agofeat(sql): add explicit type cast to Literal output
Daniele Varrazzo [Sun, 13 Mar 2022 02:35:41 +0000 (03:35 +0100)] 
feat(sql): add explicit type cast to Literal output

3 years agofeat: add `Transformer.encoding` attribute
Daniele Varrazzo [Sun, 13 Mar 2022 02:16:21 +0000 (03:16 +0100)] 
feat: add `Transformer.encoding` attribute

3 years agofeat: add Transformer.from_context() method
Daniele Varrazzo [Sat, 8 Jan 2022 23:01:56 +0000 (00:01 +0100)] 
feat: add Transformer.from_context() method

Allow to reuse the same transformer in nested context, instead of
creating new ones. Even if transformer copies are shallow, we may end up
creating several in certain places.

3 years agoMerge branch 'pipeline-more-tests'
Daniele Varrazzo [Tue, 10 May 2022 17:11:20 +0000 (19:11 +0200)] 
Merge branch 'pipeline-more-tests'

3 years agofix: make transaction status check account for pipeline mode 299/head
Denis Laxalde [Tue, 10 May 2022 10:11:21 +0000 (12:11 +0200)] 
fix: make transaction status check account for pipeline mode

We turn _check_intrans() into a generator _check_intrans_gen() in order
to call _pipeline._sync_gen() if the connection is in pipeline mode so
as to retrieve an accurate connection status.

This makes the safety guard about 'autocommit' when inside a transaction
work in pipeline mode, thus removing the xfail in transaction tests.

In test_autocommit_unknown, we now catch OperationalError which is
raised by conn.wait() rather than ProgrammingError previously which is
no longer reached.

3 years agofix: wrap transaction in an outer pipeline if the connection has one
Denis Laxalde [Tue, 10 May 2022 07:10:06 +0000 (09:10 +0200)] 
fix: wrap transaction in an outer pipeline if the connection has one

Before entering a transaction on a connection in pipeline mode, we open an
outer pipeline to ensure that a Sync is after the transaction exists;
similarly to the inner pipeline, this is to ensure that the connection
state is restored at transaction exit similarly to the non-pipeline
case. The inner pipeline is not enough because we need to account for
the exit transaction statement (COMMIT or ROLLBACK) and then sync its
result.

This fixes transactions tests failing in previous commit.

3 years agotest: parametrize transaction tests with pipeline on/off
Denis Laxalde [Tue, 10 May 2022 07:01:07 +0000 (09:01 +0200)] 
test: parametrize transaction tests with pipeline on/off

The 'conn' fixture is overloaded in transaction tests, pulling the
'pipeline' fixture to have them run with or without a pipeline.

When checking for connection's transaction state, just after entering
the transaction() block (e.g. in test_basic), we need to sync the
pipeline in order to get the state right. This is just for tests as the
exact transaction state, in pipeline mode, is not deterministic since
query results are not fetched directly.

The following tests fail:

  tests/test_transaction.py::test_basic[pipeline=on]
  tests/test_transaction.py::test_begins_on_enter[pipeline=on]
  tests/test_transaction.py::test_commit_on_successful_exit[pipeline=on]
  tests/test_transaction.py::test_rollback_on_exception_exit[pipeline=on]
  tests/test_transaction.py::test_autocommit_off_but_no_tx_started_successful_exit[pipeline=on]
  tests/test_transaction.py::test_autocommit_off_but_no_tx_started_exception_exit[pipeline=on]
  tests/test_transaction.py::test_nested_all_changes_persisted_on_successful_exit[pipeline=on]
  tests/test_transaction.py::test_nested_all_changes_discarded_on_outer_exception[pipeline=on]
  tests/test_transaction.py::test_nested_all_changes_discarded_on_inner_exception[pipeline=on]
  tests/test_transaction.py::test_nested_inner_scope_exception_handled_in_outer_scope[pipeline=on]
  tests/test_transaction.py::test_nested_three_levels_successful_exit[pipeline=on]
  tests/test_transaction.py::test_named_savepoints_successful_exit[pipeline=on]
  tests/test_transaction.py::test_explicit_rollback_of_enclosing_tx_outer_tx_unaffected[pipeline=on]
  tests/test_transaction.py::test_str[pipeline=on]

This is because the connection state is not correct at the end of
transaction, we'll fix this in next commit.

Some others were adjusted as follows:

* when entering the transaction() block, e.g. in test_begins_on_enter,
  we eventually call pipeline.sync() in order to get the state right
  (this is just for tests as the exact transaction state, in pipeline
  mode, is not deterministic since query results are not fetched
  directly);

* test_context_inerror_rollback_no_clobber[pipeline=on] is skipped, as
  explained in comment inline;

* test_prohibits_use_of_commit_rollback_autocommit[pipeline=on] is
  xfail, because Connection._check_intrans() does not check for pipeline
  mode (see TODO inline about a possible solution);

* test_str now checks for [<txstatus>, pipeline=ON] in str(Transaction).

3 years agotest: add fixtures to toggle pipeline mode
Denis Laxalde [Thu, 9 Dec 2021 15:37:50 +0000 (16:37 +0100)] 
test: add fixtures to toggle pipeline mode

Also add a pytest mark so that one can run 'pytest -m pipeline' to
select all pipeline-mode tests.

3 years agofeat: display the pipeline status in the objects repr
Daniele Varrazzo [Tue, 10 May 2022 10:10:14 +0000 (12:10 +0200)] 
feat: display the pipeline status in the objects repr

3 years agochore: bump version to release 3.0.13
Daniele Varrazzo [Tue, 10 May 2022 09:20:03 +0000 (11:20 +0200)] 
chore: bump version to release 3.0.13

3 years agoMerge branch 'fix-296'
Daniele Varrazzo [Tue, 10 May 2022 08:14:29 +0000 (10:14 +0200)] 
Merge branch 'fix-296'

3 years agodocs: suggest to use commit to maintain atomic sanity in pipeline mode 297/head
Daniele Varrazzo [Mon, 9 May 2022 23:21:47 +0000 (01:21 +0200)] 
docs: suggest to use commit to maintain atomic sanity in pipeline mode

3 years agofix: fix integration between pipelines and nested transaction
Daniele Varrazzo [Mon, 9 May 2022 23:03:13 +0000 (01:03 +0200)] 
fix: fix integration between pipelines and nested transaction

Refactor to remove all the knowledge about pipelines from the
transaction object. Replaced by just syncing before entering the
transaction.

Had to drop the pipeline exit, which will now fetch results whatever the
level. If not doing so, a final sync should have been forced to exit
with a clean state from an inner transaction block.

3 years agotest: fix test of pipeline mode and nested transaction
Daniele Varrazzo [Mon, 9 May 2022 22:57:16 +0000 (00:57 +0200)] 
test: fix test of pipeline mode and nested transaction

This test fails in the current implementation.

3 years agotest: drop TODO points and emergency rollbacks from pipeline tests
Daniele Varrazzo [Mon, 9 May 2022 21:46:47 +0000 (23:46 +0200)] 
test: drop TODO points and emergency rollbacks from pipeline tests

The previous changeset restored some sanity. The behaviour in
`test_errors_raised_on_commit` is not inconsistent with the non-pipeline
mode because the two are not comparable: in non-pipeline mode the
exception is raised by `execute()`, not by `commit()`. If an exception
is raised in `commit()` itself, it is already handled consistently, as
`test_error_on_commit` shows.

3 years agofix: wrap transaction in pipelines if the connection has one 298/head
Denis Laxalde [Mon, 9 May 2022 19:14:59 +0000 (21:14 +0200)] 
fix: wrap transaction in pipelines if the connection has one

When entering a transaction on a connection in pipeline mode, we open an
inner pipeline to ensure that a Sync is emitted at the end of
transaction thus restoring the connection in its expected state (i.e.
the same as in non-pipeline mode).

3 years agotest: add test to verify the behaviour of failed commits
Daniele Varrazzo [Mon, 9 May 2022 13:46:30 +0000 (15:46 +0200)] 
test: add test to verify the behaviour of failed commits

The exception is raised where expected; the transaction is left in IDLE
state. This is unlike what happens in pipeline mode.

3 years agofix: fix Transaction commit in pipeline mode
Daniele Varrazzo [Mon, 9 May 2022 13:36:19 +0000 (15:36 +0200)] 
fix: fix Transaction commit in pipeline mode

Make sure we receive the commit message, so we can raise an immediate
exception, as we do for connection-handled transactions.

Highlight, in the test, a behaviour difference between commit in
pipeline and non-pipeline mode. In the latter, after a failed commit,
the connection is left IDLE; in pipeline mode it is left INERROR so we
need a further rollback to keep on using it. Will look if this can be
made consistent.

3 years agofix: fix nested transaction entering in pipeline mode
Daniele Varrazzo [Mon, 9 May 2022 13:23:51 +0000 (15:23 +0200)] 
fix: fix nested transaction entering in pipeline mode

If the connection is idle, it might be that we are missing results.
Receive them to align the connection state to what the transaction
object expects, otherwise the assert in _push_savepoint() will fail.

3 years agofix: sync the pipeline on commit()
Daniele Varrazzo [Mon, 9 May 2022 00:57:05 +0000 (02:57 +0200)] 
fix: sync the pipeline on commit()

This maintains the expectation that, after commit(), the operation is
really persisted. As per postgres pipeline docs:

    The client must not assume that work is committed when it sends a
    COMMIT — only when the corresponding result is received to confirm the
    commit is complete.

With this change we are effectively receiving the result of the commit,
eventually throwing an exception if it happened.

Close #296

3 years agofix: fetch results on Pipeline.sync().
Daniele Varrazzo [Mon, 9 May 2022 00:52:39 +0000 (02:52 +0200)] 
fix: fetch results on Pipeline.sync().

This allows a sync() call to establish an high level synchronization
point between the application and the server. If there were errors in
the processing so far, sync will throw the exception.

See #296.

3 years agodocs: add warning about error messages raised randomly in pipeline mode
Daniele Varrazzo [Sun, 8 May 2022 23:36:40 +0000 (01:36 +0200)] 
docs: add warning about error messages raised randomly in pipeline mode

Close #266

3 years agofix: raise a clean error on pipeline() on a closed connection
Daniele Varrazzo [Sun, 8 May 2022 20:26:28 +0000 (22:26 +0200)] 
fix: raise a clean error on pipeline() on a closed connection

3 years agochore: update cibuildwheel to 2.5.0
Daniele Varrazzo [Mon, 2 May 2022 01:01:11 +0000 (03:01 +0200)] 
chore: update cibuildwheel to 2.5.0

3 years agoMerge branch 'fix-293'
Daniele Varrazzo [Sun, 8 May 2022 20:14:16 +0000 (22:14 +0200)] 
Merge branch 'fix-293'

3 years agoFix array oid dumping lists of integer
Daniele Varrazzo [Sun, 8 May 2022 14:29:32 +0000 (16:29 +0200)] 
Fix array oid dumping lists of integer

The problem was only in the list text dumper, which was trying to do more
than what needed. The list binary dumper worked alright.

Drop mixed array test, which don't really represent anything Postgres
can work with.

Close #293

3 years agotest: add test to verify the wrong array oid with numbers
Daniele Varrazzo [Thu, 5 May 2022 21:04:10 +0000 (23:04 +0200)] 
test: add test to verify the wrong array oid with numbers

The array binary dumper does the right thing; the text one picks
numeric[] unconditionally. It was clearly made on purpose, but #293
shows that it's a bad idea.

3 years agodocs: wordsmith pipeline docs
Daniele Varrazzo [Sun, 8 May 2022 14:24:17 +0000 (16:24 +0200)] 
docs: wordsmith pipeline docs

3 years agodocs: drop repeated sentence
Daniele Varrazzo [Sat, 7 May 2022 18:21:43 +0000 (20:21 +0200)] 
docs: drop repeated sentence

3 years agoMerge branch 'pipeline-docs'
Daniele Varrazzo [Sat, 7 May 2022 18:08:23 +0000 (20:08 +0200)] 
Merge branch 'pipeline-docs'

3 years agodocs: typo fixed 263/head
Daniele Varrazzo [Sat, 7 May 2022 17:59:49 +0000 (19:59 +0200)] 
docs: typo fixed

Thank you @dlax!

3 years agodocs: add examples and messages details in pipeline mode
Daniele Varrazzo [Sat, 7 May 2022 17:57:50 +0000 (19:57 +0200)] 
docs: add examples and messages details in pipeline mode

3 years agodocs: mention that conn.pipeline() yields a Pipeline object 295/head
Denis Laxalde [Sat, 7 May 2022 15:49:43 +0000 (17:49 +0200)] 
docs: mention that conn.pipeline() yields a Pipeline object

While reading the section, it is otherwise not obvious to understand
where to get the Pipeline object from.

3 years agodocs: add note about implicit transactions and sync in pipeline mode
Daniele Varrazzo [Sat, 7 May 2022 15:29:25 +0000 (17:29 +0200)] 
docs: add note about implicit transactions and sync in pipeline mode

3 years agodocs: split/reshuffle pipeline docs
Daniele Varrazzo [Sat, 7 May 2022 14:54:51 +0000 (16:54 +0200)] 
docs: split/reshuffle pipeline docs

- Postgres concept
- Psycopg usage
- detail about sync points
- disclaimer - don't call the semver police.

3 years agodocs: document that now rollback issues a sync point
Daniele Varrazzo [Sat, 7 May 2022 14:53:34 +0000 (16:53 +0200)] 
docs: document that now rollback issues a sync point

3 years agodocs: add warning disclaimer about pipeline mode
Daniele Varrazzo [Sat, 7 May 2022 14:21:07 +0000 (16:21 +0200)] 
docs: add warning disclaimer about pipeline mode

3 years agodocs: clarify flush and sync pipeline operations
Denis Laxalde [Sun, 3 Apr 2022 19:59:55 +0000 (21:59 +0200)] 
docs: clarify flush and sync pipeline operations

3 years agodocs: fix pipeline docs typos
Daniele Varrazzo [Sun, 3 Apr 2022 18:37:44 +0000 (20:37 +0200)] 
docs: fix pipeline docs typos

3 years agodocs: add note about features not supported in pipeline mode
Daniele Varrazzo [Sun, 3 Apr 2022 00:25:55 +0000 (02:25 +0200)] 
docs: add note about features not supported in pipeline mode

3 years agodocs: add first cut of pipeline mode docs
Daniele Varrazzo [Sat, 2 Apr 2022 22:55:18 +0000 (00:55 +0200)] 
docs: add first cut of pipeline mode docs

3 years agofix: sync pipeline state on rollback 267/head
Daniele Varrazzo [Mon, 4 Apr 2022 01:41:49 +0000 (03:41 +0200)] 
fix: sync pipeline state on rollback