Commit Graph

922 Commits

Author SHA1 Message Date
Daniele Varrazzo
6e5abf33f2 Merge branch 'fix-547' 2017-04-19 01:34:39 +01:00
Daniele Varrazzo
a7e3f46431 Merge remote-tracking branch 'fix_lobject_factory' 2017-04-19 01:06:24 +01:00
Daniele Varrazzo
248e653c9e Fixed args parsing in ReplicationCursor.consume_stream()
Close #547.
2017-04-19 01:01:59 +01:00
Frazer McLean
7b3ea43e92 Handle lobject mode=None correctly 2017-04-16 03:20:31 +02:00
Frazer McLean
38cd720369 Fix name of lobject keyword argument 2017-04-16 03:12:18 +02:00
Daniele Varrazzo
a66c34a6d0 Don't clobber a Python exception with an unknown error
Close #410
2017-04-05 14:54:07 +01:00
Daniele Varrazzo
7214c6652e Return objects with timezone parsing infinity timestamptz
Close #536.
2017-03-22 03:03:02 +00:00
Daniele Varrazzo
ba0329fb40 replication connection init refactored to use psyco_make_dsn
Some extra bonus refactoring to improve the function readability (don't
reuse names for variables with different refcount rules, don't pass
separate obj/self, async pass-through...)
2017-03-16 03:55:22 +00:00
Daniele Varrazzo
9f160fd820 Obscure the password on url dsn too
Note that we don't leak anymore the password length.

Fix #528
2017-03-16 03:53:40 +00:00
Daniele Varrazzo
103655d670 Password scrubbing refactored in a separate function 2017-03-15 16:04:45 +00:00
Greg Ward
12317557da Always raise OperationalError when connection was closed externally.
From the DB-API (https://www.python.org/dev/peps/pep-0249/):

  OperationalError

  Exception raised for errors that are related to the database's
  operation and not necessarily under the control of the programmer,
  e.g. an unexpected disconnect occurs, [...]

Additionally, psycopg2 was inconsistent, at least in the async case:
depending on how the "connection closed" error was reported from the
kernel to libpq, it would sometimes raise OperationalError and
sometimes DatabaseError. Now it always raises OperationalError.
2017-03-14 12:14:00 +00:00
Greg Ward
b203a7c775 Always detect when a connection is closed behind psycopg2's back.
There's a race condition that only seems to happen over Unix-domain
sockets. Sometimes, the closed socket is reported by the kernel to
libpq like this (captured with strace):

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = 29
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, 0x12d0330, 16384, 0, 0, 0)  = -1 ECONNRESET (Connection reset by peer)

That is, psycopg2/libpq sees no error when sending the first query
after the connection is closed, but gets an error reading the result.
In that case, everything worked fine.

But sometimes, the error manifests like this:

  sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe)
  recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0
  recvfrom(3, "", 16274, 0, NULL, NULL)   = 0

i.e. libpq received an error when sending the query. This manifests as
a slightly different exception from a slightly different place. More
importantly, in this case connection.closed is left at 0 rather than
being set to 2, and that is the bug I'm fixing here.

Note that we see almost identical behaviour for sync and async
connections, and the fixes are the same. So I added extremely similar
test cases.

Finally, there is still a bug here: for async connections, we
sometimes raise DatabaseError (incorrect) and sometimes raise
OperationalError (correct). Will fix that next.
2017-03-14 12:08:03 +00:00
Daniele Varrazzo
26bd5df048 Don't use PG_INT64_TYPE
Only defined in Postgres 9.3

Should close #520, but let's wait for the CI response (build on
Windows etc.)
2017-03-02 19:32:39 +00:00
Daniele Varrazzo
72f74d1f41 Dropped compiler warning on Windows 2017-02-24 13:33:42 +00:00
Daniele Varrazzo
691df4952b Handle overflow in interval parsing 2017-02-24 13:23:56 +00:00
Daniele Varrazzo
3b665d35d5 Make sure to use 64 bits in interval parsing accumulators 2017-02-24 12:10:54 +00:00
Daniele Varrazzo
834e9996da Parse interval only using integers
(almost... except for micros rounding)

While this is probably an improvement on the previous implementation,
I am largely waving a dead chicken at windows, which keeps failing to
pass the seconds overflow test. If it doesn't pass now either I'll start
blaming Python's timedelta.
2017-02-24 03:48:41 +01:00
Daniele Varrazzo
a15dfbbd4f Try to fix the same problem in windows
Previous commit doesn't pass on Windows: it looks like window's floor()
has an integer overflow.
2017-02-24 02:41:34 +01:00
Daniele Varrazzo
14fe3ad8c9 Fixed integer overflow in interval typecaster
Close #512.
2017-02-24 02:10:27 +01:00
Daniele Varrazzo
61101888e4 Revert default_transaction_* to default only if set
When moving from autocommit True -> False reset only the server
parameters that were actually specified by psycopg to honour the
serssion characteristics.
2017-02-16 13:15:14 +00:00
Daniele Varrazzo
d7bba865f3 Check for deferrable unsupported applied to attribute too 2017-02-16 13:14:45 +00:00
Daniele Varrazzo
d50ed48807 Added readonly and deferrable attributes 2017-02-16 12:46:35 +00:00
Daniele Varrazzo
b5d80b609d Revert pre-2.7b1 behaviour of silent rollback on conn.set_isolation_level()
Legacy method is legacy.
2017-02-16 12:46:35 +00:00
Daniele Varrazzo
20c9c17457 connection.isolation_level is now writable 2017-02-16 12:46:35 +00:00
Jason Erickson
32e81a27b5 Allowed inittype.h's defs all versions of MSVC
Apparently only MSVC 2015 x64 had defined these types.  Changed check to
work for all versions of MSVC.  Does not affect 2015x64.
2017-02-10 10:14:17 -07:00
Jason Erickson
7493ea24f2 Defined inttypes.h for older MSVC compilers
Older MSVC compilers do not support the C99 standard
2017-02-09 22:27:18 -07:00
Jason Erickson
d52e9100d2 Added support for MSVC compiler
Added function 'timeradd'.
Changed second parameter of 'gettimeofday' to void since not used in
function and MSVC timezone definition is not a struct).
2017-02-09 20:57:54 -07:00
Jason Erickson
83cf908c88 Fixed MSVC compiler error and warning
MSVC doesn't like referencing new initialized variables in the variable
declaration section.
2017-02-09 20:54:29 -07:00
Daniele Varrazzo
d2cd1236a8 Dropped compiler warning about signed/unsigned comparisons 2017-02-08 08:44:08 +00:00
Daniele Varrazzo
3e12522bc9 Don't convert '{}'::unknown into an empty list
Close #506.
2017-02-08 08:43:53 +00:00
Daniele Varrazzo
28c489f17e Merge branch 'no-set-default-session' 2017-02-07 00:58:54 +00:00
Daniele Varrazzo
7485fabe4f Fixed BEGIN; SET TRANSACTION with PG 7.4 2017-02-07 00:58:29 +00:00
Daniele Varrazzo
3fbff5d848 Give precedence to '__conform__()' over superclasses choosing adapter
Close #456
2017-02-05 11:54:50 +01:00
Daniele Varrazzo
9054eeccc0 Set default_transaction_* GUC if session state is changed in autocomit 2017-02-04 15:19:41 +00:00
Daniele Varrazzo
c60682c230 Reuse set_session to implement autocommit, set_isolation_level 2017-02-04 13:26:43 +00:00
Daniele Varrazzo
8527144173 Better separation between interface and state change code
The state change function has a C callable signature.
2017-02-04 13:01:11 +00:00
Daniele Varrazzo
c1e016e597 Don't use default_transaction_* for session characteristics
Store the state in the connection object and set the params on BEGIN

Some tests fail: a few can be fixed reading transaction_* instead of
default_transaction_*; but the behaviour of tx characteristics with
autocommit is effectively changed. It may be addressed by setting
default_transaction_* if autocommit is set.
2017-02-04 02:38:56 +00:00
Daniele Varrazzo
9863637f30 Dropped compiler warning in debug mode 2017-02-04 02:32:26 +00:00
Daniele Varrazzo
de8b335d80 Merge branch 'master' into sql-compose 2017-02-03 04:56:02 +00:00
Daniele Varrazzo
ce9be69615 Added async_ as an alias for async
Added in argument for psycopg2.connect() and connection.__init__, and
for the connection.async attribute.
2017-02-03 04:43:49 +00:00
Daniele Varrazzo
828415d476 Typo: composible -> composable 2017-01-01 06:32:18 +01:00
Daniele Varrazzo
600416aafc Fixed sql stuff in Py3 2017-01-01 05:59:21 +01:00
Daniele Varrazzo
c4a67fc1c1 Added sql.compose() implementation 2017-01-01 05:23:42 +01:00
Daniele Varrazzo
449bd4485f Merge branch 'fast-codecs' 2016-12-29 22:15:46 +01:00
Daniele Varrazzo
cb5293be1f Use the proper API functions to look up codec functions 2016-12-29 22:11:58 +01:00
Daniele Varrazzo
3295beb777 Don't look up for Python encoding
Store the encode/decode functions for the right codec in the connection.
The Python encoding name has been dropped of the connection to avoid the
temptation to use it...
2016-12-29 22:11:58 +01:00
Daniele Varrazzo
a81f12f9bd Don't set tp_compare on Python 3
The slot is unused in Py < 3.5, and replaced by pg_as_async in Py 3.5.
2016-12-29 21:43:04 +01:00
Daniele Varrazzo
dfe547856e Use -1 instead of 0 to say "calculate the length" in many funcs
0 is a valid length, isn't it?
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
a255e4e1c6 Store python encoding and decoding functions in the connection
Unused for now: will be used instead of 'pyenc', which is to be dropped.
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
17a74cc771 Setting connection encoding refactored
Code paths to read encoding on connection and to store the new
connection in the structure after changing it in the backend unified
into a single function.
2016-12-26 16:51:22 +01:00