]> git.ipfire.org Git - thirdparty/psycopg.git/log
thirdparty/psycopg.git
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

3 years agoMerge branch 'pipeline-sync-no-fetch'
Daniele Varrazzo [Sat, 7 May 2022 13:12:56 +0000 (15:12 +0200)] 
Merge branch 'pipeline-sync-no-fetch'

3 years agofeat: only Sync nested pipelines at exit 269/head
Denis Laxalde [Wed, 6 Apr 2022 18:01:53 +0000 (20:01 +0200)] 
feat: only Sync nested pipelines at exit

It's not needed to force a results fetch when exiting a nested pipeline
as this would naturally happen either later in the outer pipeline or
eventually at the end of the outermost one. Rather, just do a Sync, as
it allows outer pipeline to resume normal execution in case the inner
one got into aborted state.

3 years agofix: only request a pipeline flush in returning executemany()
Denis Laxalde [Mon, 4 Apr 2022 15:19:55 +0000 (17:19 +0200)] 
fix: only request a pipeline flush in returning executemany()

A full Sync is not needed as we're only interested in getting results
when returning=True.

3 years agofix: do not fetch in Pipeline.sync()
Denis Laxalde [Mon, 4 Apr 2022 09:41:06 +0000 (11:41 +0200)] 
fix: do not fetch in Pipeline.sync()

During previous refactorings, we made Pipeline.sync() also fetch results
from the server. But this somehow breaks the semantics of the
synchronization point as defined by Postgres because the user might be
interested in emitting Sync message as a way to solely close the current
series of queries in the pipeline: i.e., flush queries from client to
server and reset the pipeline error state. In this respect, the 'fetch'
step should be explicit.

BasePipeline._sync_gen() is changed to only emit a Sync and a new
_exit_gen() method is introduced doing what _sync_gen() previously did.
Accordingly, the warning emitted when calling this _exit_gen() at
pipeline exit is adjusted to say "terminating" instead of "syncing".

3 years agofix: shorten tracebacks on pipeline sync and exit
Daniele Varrazzo [Mon, 4 Apr 2022 00:54:41 +0000 (02:54 +0200)] 
fix: shorten tracebacks on pipeline sync and exit

The details shown are only the communication bowels. So we go from:

    Traceback (most recent call last):
      File "trace.py", line 301, in <module>
        conn.execute("select pg_sleep(0.2)")
      File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
        next(self.gen)
      File "/home/piro/dev/psycopg3/psycopg/psycopg/connection.py", line 881, in pipeline
        yield pipeline
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 197, in __exit__
        self.sync()
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 183, in sync
        self._conn.wait(self._sync_gen())
      File "/home/piro/dev/psycopg3/psycopg/psycopg/connection.py", line 896, in wait
        return waiting.wait(gen, self.pgconn.socket, timeout=timeout)
      File "/home/piro/dev/psycopg3/psycopg/psycopg/waiting.py", line 237, in wait_epoll
        s = gen.send(ready)
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 92, in _sync_gen
        yield from self._communicate_gen()
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 105, in _communicate_gen
        self._process_results(queued, results)
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 149, in _process_results
        raise e.error_from_result(result, encoding=pgconn_encoding(self.pgconn))
    psycopg.errors.UndefinedColumn: column "foo" does not exist
    LINE 1: select foo
                   ^

to:

    Traceback (most recent call last):
      File "trace.py", line 301, in <module>
        conn.execute("select pg_sleep(0.2)")
      File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
        next(self.gen)
      File "/home/piro/dev/psycopg3/psycopg/psycopg/connection.py", line 881, in pipeline
        yield pipeline
      File "/home/piro/dev/psycopg3/psycopg/psycopg/_pipeline.py", line 205, in __exit__
        raise exc2.with_traceback(None)
    psycopg.errors.UndefinedColumn: column "foo" does not exist
    LINE 1: select foo
                   ^

which shows much more clearly that the traceback was raised at pipeline
block exit.

3 years agofix: allow to use cancel() on a closed connection
Daniele Varrazzo [Mon, 2 May 2022 00:45:21 +0000 (02:45 +0200)] 
fix: allow to use cancel() on a closed connection

3 years agodocs: add hint about using add_signal_handler() to interrupt async queries
Daniele Varrazzo [Mon, 2 May 2022 00:37:00 +0000 (02:37 +0200)] 
docs: add hint about using add_signal_handler() to interrupt async queries

Courtesy @gjcarneiro, thank you!

3 years agoMerge branch 'fix-286'
Daniele Varrazzo [Mon, 2 May 2022 00:53:32 +0000 (02:53 +0200)] 
Merge branch 'fix-286'

3 years agoperf: avoid unnecessary recvfrom() in cursor.stream()
Daniele Varrazzo [Sun, 1 May 2022 22:56:42 +0000 (00:56 +0200)] 
perf: avoid unnecessary recvfrom() in cursor.stream()

Call PQisBusy() before PQconsumeInput() on fetching results. If not
busy, don't call PQconsumeInput() at all but just go to fetching results
and notifications.

This is especially useful in single-row mode because most of the times
the libpq can produce several results after a single network fetch.
Previously we were calling PQconsumeInput() also when results were
already on the client and there was nothing new to read, which forced
the libpq to run a select() to tell apart a lack of data from an EOF,
see `the grumble`_, and caused the overhead reported in #286.

Close #286.

.. _the grumble: https://github.com/postgres/postgres/blob/ed57cac84d1c5642737dab1e4c4b8cb4f0c4305f/src/interfaces/libpq/fe-misc.c#L681

3 years agotest: add cursor.stream() test for empty result sets
Daniele Varrazzo [Sun, 1 May 2022 20:45:24 +0000 (22:45 +0200)] 
test: add cursor.stream() test for empty result sets

Also add a missing async test for results with no column.

3 years agorefactor: replace an assert with a type: ignore
Daniele Varrazzo [Sun, 1 May 2022 20:44:37 +0000 (22:44 +0200)] 
refactor: replace an assert with a type: ignore

It's not like we give away opcodes for free here.

3 years agorefactor: send only once per stream
Daniele Varrazzo [Sun, 1 May 2022 12:35:02 +0000 (14:35 +0200)] 
refactor: send only once per stream

No need to do it at every row, probably entirely wrong. However this is
not the cause of the slowness reported in #286.

3 years agorefactor: only clean up the wait() timeout if needed
Daniele Varrazzo [Sun, 1 May 2022 12:30:20 +0000 (14:30 +0200)] 
refactor: only clean up the wait() timeout if needed

Often we terminate the iteration at the first item, so no need to select
at all.

3 years agoRe-export from psycopg._cmodule
hauntsaninja [Sun, 1 May 2022 05:44:04 +0000 (23:44 -0600)] 
Re-export from psycopg._cmodule

3 years agotest: fix variable scope in ctrl-c test
Daniele Varrazzo [Sat, 30 Apr 2022 13:18:14 +0000 (15:18 +0200)] 
test: fix variable scope in ctrl-c test

3 years agotest: verify ctrl-c in async mode using get_event_loop
Daniele Varrazzo [Fri, 29 Apr 2022 23:16:02 +0000 (01:16 +0200)] 
test: verify ctrl-c in async mode using get_event_loop

3 years agotest: drop test guard for unsupported Python version
Daniele Varrazzo [Fri, 29 Apr 2022 23:54:04 +0000 (01:54 +0200)] 
test: drop test guard for unsupported Python version

3 years agodocs: document psycopg 3.0.12 released
Daniele Varrazzo [Fri, 29 Apr 2022 22:42:19 +0000 (00:42 +0200)] 
docs: document psycopg 3.0.12 released

3 years agodocs: improvements to the copy docs
Daniele Varrazzo [Fri, 29 Apr 2022 22:28:07 +0000 (00:28 +0200)] 
docs: improvements to the copy docs

3 years agodocs: add example of table copy across server
Daniele Varrazzo [Fri, 29 Apr 2022 22:07:47 +0000 (00:07 +0200)] 
docs: add example of table copy across server

See #285 for a conversation.

3 years agodocs: document that ticket #254 is fixed in 3.0.12
Daniele Varrazzo [Fri, 29 Apr 2022 21:42:20 +0000 (23:42 +0200)] 
docs: document that ticket #254 is fixed in 3.0.12

We can consider this just a bug, not a change of interface. It is
particularly bad because it doesn't allow to pipe a COPY FROM into a
COPY TO.

See https://github.com/psycopg/psycopg/discussions/285#discussioncomment-2663192
for details.

3 years agotest: add tests to verify copy across tables works
Daniele Varrazzo [Fri, 29 Apr 2022 21:39:36 +0000 (23:39 +0200)] 
test: add tests to verify copy across tables works

3 years agodocs: cleanup in types/enums docs
Daniele Varrazzo [Fri, 29 Apr 2022 20:46:31 +0000 (22:46 +0200)] 
docs: cleanup in types/enums docs

3 years agotypo fix
Utsav [Thu, 28 Apr 2022 02:28:23 +0000 (22:28 -0400)] 
typo fix

3 years agoMerge branch 'enum'
Daniele Varrazzo [Fri, 22 Apr 2022 17:14:31 +0000 (19:14 +0200)] 
Merge branch 'enum'

3 years agodocs(enum): typo-fix and rephrase 274/head
Denis Laxalde [Fri, 22 Apr 2022 06:38:40 +0000 (08:38 +0200)] 
docs(enum): typo-fix and rephrase

3 years agodocs(enum): restyle news entry
Daniele Varrazzo [Fri, 22 Apr 2022 01:34:35 +0000 (03:34 +0200)] 
docs(enum): restyle news entry

3 years agofeat(enum): add mapping override to `register_enum()`
Daniele Varrazzo [Fri, 22 Apr 2022 00:48:41 +0000 (02:48 +0200)] 
feat(enum): add mapping override to `register_enum()`

3 years agotest(enum): drop several hundreds of redundant tests
Daniele Varrazzo [Fri, 22 Apr 2022 00:25:40 +0000 (02:25 +0200)] 
test(enum): drop several hundreds of redundant tests

No need to exhaustively test encodings on ascii data or array properties
tested elsewhere.

3 years agorefactor(enum): introduce an explicit dump/load mapping
Daniele Varrazzo [Thu, 21 Apr 2022 14:04:32 +0000 (16:04 +0200)] 
refactor(enum): introduce an explicit dump/load mapping

This will allow mapping customization; it is also slightly faster
because it doesn't require data encoding/decoding.

3 years agofix(enum): raise DataError in case of labels mismatch on load
Daniele Varrazzo [Thu, 21 Apr 2022 08:47:11 +0000 (10:47 +0200)] 
fix(enum): raise DataError in case of labels mismatch on load

A DataError subclass is already raised on mismatch on dump. Be
consistent.

3 years agofix(enum): move `enum` arg of register_enum() as third item
Daniele Varrazzo [Thu, 21 Apr 2022 08:22:44 +0000 (10:22 +0200)] 
fix(enum): move `enum` arg of register_enum() as third item

This is more consistent with the other register_*() functions and allow
a more natural order of arguments if others must be added (e.g.
mapping).

3 years agotest(enum): refactor in order to write enum-specific type
Daniele Varrazzo [Thu, 21 Apr 2022 08:21:18 +0000 (10:21 +0200)] 
test(enum): refactor in order to write enum-specific type

They all get created, tests can choose to use only some of them.

3 years agotest(enum): drop unneeded cursor creation
Daniele Varrazzo [Thu, 21 Apr 2022 01:48:00 +0000 (03:48 +0200)] 
test(enum): drop unneeded cursor creation

3 years agodocs(enum): document the behaviour of unregistered and registered enums
Daniele Varrazzo [Wed, 20 Apr 2022 11:26:57 +0000 (13:26 +0200)] 
docs(enum): document the behaviour of unregistered and registered enums

3 years agotest(enum): add tests to verify the behaviour of unregistered enums
Daniele Varrazzo [Wed, 20 Apr 2022 11:26:37 +0000 (13:26 +0200)] 
test(enum): add tests to verify the behaviour of unregistered enums

3 years agorefactor(enum): rename python_type -> enum, enum_labels -> labels on EnumInfo
Daniele Varrazzo [Mon, 18 Apr 2022 17:23:32 +0000 (19:23 +0200)] 
refactor(enum): rename python_type -> enum, enum_labels -> labels on EnumInfo

The previous name were lifted from the composite adapters. However, that
class would have had a more ambiguous "type" attribute, and "types" for
the fields, hence the decision of using "python_" and "fields_" prefix
to disambiguate.

In the enum adapters context, enum is not ambiguous, so a more natural
name seems preferred.

3 years agofeat(enum): dump enums by keys instead of values
Daniele Varrazzo [Mon, 18 Apr 2022 17:15:35 +0000 (19:15 +0200)] 
feat(enum): dump enums by keys instead of values

This removes the need for enums to be str-based. It also removes the
asymmetry whereby automatically generated enums were *not* string based,
but pure enums.

3 years agorefactor: add conn_encoding function
Daniele Varrazzo [Thu, 21 Apr 2022 13:49:55 +0000 (15:49 +0200)] 
refactor: add conn_encoding function

Simplifies the chore of obtaining an encoding from the connection,
defaulting to utf-8 if not available.

3 years agotest(enum): add test to verify enums work with sql_ascii connections
Daniele Varrazzo [Sun, 17 Apr 2022 22:52:27 +0000 (00:52 +0200)] 
test(enum): add test to verify enums work with sql_ascii connections

3 years agotest(enum): typo fixed
Daniele Varrazzo [Sun, 17 Apr 2022 22:45:44 +0000 (00:45 +0200)] 
test(enum): typo fixed

3 years agotest(enum): more idiomatic sql composition
Daniele Varrazzo [Sun, 17 Apr 2022 22:44:43 +0000 (00:44 +0200)] 
test(enum): more idiomatic sql composition

3 years agotest(enum): disable Enum random testing
Daniele Varrazzo [Fri, 15 Apr 2022 05:33:12 +0000 (07:33 +0200)] 
test(enum): disable Enum random testing

3 years agotest(enum): added async tests from enums
Vladimir Osokin [Thu, 14 Apr 2022 11:03:26 +0000 (16:03 +0500)] 
test(enum): added async tests from enums

3 years agorefactor(enum): removed redundant `EnumDumper.dump` method override
Vladimir Osokin [Thu, 14 Apr 2022 10:49:09 +0000 (15:49 +0500)] 
refactor(enum): removed redundant `EnumDumper.dump` method override

3 years agofix(enum): code review fixes
Vladimir Osokin [Thu, 14 Apr 2022 10:37:56 +0000 (15:37 +0500)] 
fix(enum): code review fixes

* moved documentation to `docs/basic/adapt.rst`;
* use encoding in `EnumLoader`;
* oid-based dumpers;
* rewritten tests;
* minor fixes.

3 years agotest(enum): add failing tests to illustrate enum needed improvements
Daniele Varrazzo [Thu, 14 Apr 2022 01:08:59 +0000 (03:08 +0200)] 
test(enum): add failing tests to illustrate enum needed improvements

3 years agofeat: add enum support
Vladimir Osokin [Wed, 13 Apr 2022 11:49:14 +0000 (16:49 +0500)] 
feat: add enum support

3 years agofix: fix dumping int enums in text mode, python implementation
Daniele Varrazzo [Thu, 21 Apr 2022 01:29:05 +0000 (03:29 +0200)] 
fix: fix dumping int enums in text mode, python implementation

The error was hidden by a broken test, failing to test the text mode.

3 years agodocs: a few clarifications about composite adaptation
Daniele Varrazzo [Tue, 12 Apr 2022 22:22:04 +0000 (00:22 +0200)] 
docs: a few clarifications about composite adaptation

3 years agofix: drop debug logging left over
Daniele Varrazzo [Thu, 7 Apr 2022 17:57:07 +0000 (19:57 +0200)] 
fix: drop debug logging left over

3 years agodoc: add PipelineStatus to 'pq' page
Denis Laxalde [Mon, 4 Apr 2022 06:39:36 +0000 (08:39 +0200)] 
doc: add PipelineStatus to 'pq' page

3 years agofeat: add ConnectionInfo.pipeline_status
Daniele Varrazzo [Sun, 3 Apr 2022 21:33:55 +0000 (23:33 +0200)] 
feat: add ConnectionInfo.pipeline_status

3 years agodocs: clean up a couple of sentences
Daniele Varrazzo [Sun, 3 Apr 2022 23:26:42 +0000 (01:26 +0200)] 
docs: clean up a couple of sentences

- New version scheme is "starting from PG 10", not "after PG 10" (also,
  chunky bit moved from docstring to docs as for most other docs).
- The transaction status is of the session, not the server.

3 years agoMerge branch 'executemany-pipeline'
Daniele Varrazzo [Sat, 2 Apr 2022 23:23:30 +0000 (01:23 +0200)] 
Merge branch 'executemany-pipeline'

3 years agofeat: add PipelineAborted exception 260/head
Daniele Varrazzo [Sat, 2 Apr 2022 23:06:17 +0000 (01:06 +0200)] 
feat: add PipelineAborted exception

It is a condition that likely will have to be managed, so let's not
clobber it with other OperationalError.

3 years agofix: don't fail assert if fetching without result in pipeline mode
Daniele Varrazzo [Sat, 2 Apr 2022 01:44:26 +0000 (03:44 +0200)] 
fix: don't fail assert if fetching without result in pipeline mode

The error can be triggered easily by the user. The condition is handled
just naturally by all the methods calling _fetch_pipeline().

3 years agofix: consistent sync/exit and error management in pipeline contexts
Daniele Varrazzo [Tue, 29 Mar 2022 23:57:06 +0000 (01:57 +0200)] 
fix: consistent sync/exit and error management in pipeline contexts

Don't clobber an exception on exit of the nested block too. In order to
simplify the code, make the pipeline count the number of time it is
entered, and call _exit() only the last time it exits.

Drop assert that we have left pipeline mode leaving the block. If we get
in unrecoverable state, we will have not. By now we should probably just
close the connection; however, leaving it this way is a better
indication that the connection is broken because of something about
pipeline mode; closing it would hide it, and even if we raised a
warning, it would be much easier to miss it than to miss the exceptions
raised in broken state.

3 years agofix: forbid COPY in pipeline mode
Daniele Varrazzo [Tue, 29 Mar 2022 23:54:56 +0000 (01:54 +0200)] 
fix: forbid COPY in pipeline mode

COPY is not supported. Attempting it puts the connection in
unrecoverable state, with pipeline sync failing and pipeline exit
complaining that there are still results. So let's try to not get in
that state.

3 years agofix: restore sending a Sync on block exit but not on executemany end
Daniele Varrazzo [Tue, 29 Mar 2022 20:03:49 +0000 (22:03 +0200)] 
fix: restore sending a Sync on block exit but not on executemany end

It was removed a few commits ago, but as Denis suggests, it makes sense
to keep it. Reintroduce it (and test for it), but make sure executemany
doesn't send extra sync.

3 years agotest: add test to verify the number of roundtrips in pipelined executemany
Daniele Varrazzo [Tue, 29 Mar 2022 19:36:46 +0000 (21:36 +0200)] 
test: add test to verify the number of roundtrips in pipelined executemany

Add fixture to access the trace data as Python object. I think it's cute <3

3 years agotest: add fixture to write tests based on libpq trace data
Daniele Varrazzo [Tue, 29 Mar 2022 19:35:48 +0000 (21:35 +0200)] 
test: add fixture to write tests based on libpq trace data

3 years agofix: make no-tuple results available after executemany returning
Daniele Varrazzo [Tue, 29 Mar 2022 12:29:11 +0000 (14:29 +0200)] 
fix: make no-tuple results available after executemany returning

There could be useful info there, if the user asks for it. Now this
doesn't slow down the happy execute path, because the default of
returning is False.

3 years agofix: only flush the pipeline after executemany if returning
Daniele Varrazzo [Tue, 29 Mar 2022 12:26:26 +0000 (14:26 +0200)] 
fix: only flush the pipeline after executemany if returning

This has the side effect of breaking rowcount, as before, but can send
many executemany in the same pipeline.

`rowcount` is correct if `returning=True` is set instead, which is a
thing we can at least document, and makes sense: "if you want a result,
you flush the pipeline, dude".