Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g84SU-0000xw-Iq for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 14:18:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g84SS-0005nJ-RC for psycopg@arkaria.postgresql.org; Thu, 04 Oct 2018 14:18:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g84SS-0005n8-FM for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 14:18:28 +0000 Received: from mail-vs1-xe42.google.com ([2607:f8b0:4864:20::e42]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g84SL-0000R6-Ms for psycopg@lists.postgresql.org; Thu, 04 Oct 2018 14:18:27 +0000 Received: by mail-vs1-xe42.google.com with SMTP id w16-v6so5447471vso.9 for ; Thu, 04 Oct 2018 07:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zzzcomputing-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FGgshSskd/ARsAfqfNuK6C6vvFdk9FG3KVwANHqAgA8=; b=soxHmg0hXQ1YQN4itEyxxt/AjMeXcJlfwOlFBVuqn8kGDMQBXzwjWHP/L9QhixKK5s 0N6QZJybgjpQVP9NZ7xsjcbfu6D3aO7of8Tqe0hx/O0mr5xSBN9q4yZlq7ZkZVduHT8f Oo1thXlUT9cQi6NjgWRxdImqdZEqP8rvTQ+zoKBBkRtGzc9HQB9Gh4+1ktE95taVkLVc QpKF7g0LaE+5XqHHRky29dxZNzvriMIy3P6ynhI21BIs036qRT5/LUqam9IFJ92/dZ/4 6MOedYyAPhh8LiWafKPbZ8mXPg+/GdeKb6XsjjJuEB33K4i8MM3hAR91nXCm5jgplyll ar3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FGgshSskd/ARsAfqfNuK6C6vvFdk9FG3KVwANHqAgA8=; b=it5M6pGsMoysAPXW6w45IcHpalkEqAoUQtCjPjazjU2kvzh4tx6NrB2atAxWwOhZnC qjf1/OYvmNJ+M4mE2mazJ/NXicJR2h2o6UqE1rkErvRo1qYPnnrw6/l3MH9oECji3ZdR bJIUYf+m9rTpCzyt9DqiyqjIIW2LqEGcknPKX3pe7Q5ngPN+pjwE7o8tX9QwSbxI9pV3 qpg5JTQC6DCi5uwZ1ZWJezZ26q/wXSVW75tcOapVZ57PFDuvLhOKRUSD4f8NoYKoz5ln 2TBKGrdEi+OYgjR9WnXdscC1dHMB8byiQMfxlk81kiNywteG0hwjeBEr2MDDi93FpwXz yWZg== X-Gm-Message-State: ABuFfog8FQ0pVud7SuLx1L95YKFoII+n5bvZKvTpsnRF5DBy30j/f9y+ 9gEV/ROpxwMEO0eSXfvU+yVhb5VN9msvcVHfwcJpwA== X-Google-Smtp-Source: ACcGV60pCU4rKFr8GCcBMqNZdU6S5KMYdluw0JVjPajJCW54AxBrsxFnXW+ASQybQaKAzbRtwRLt+blca9+EzlFHD4s= X-Received: by 2002:a67:c10c:: with SMTP id d12mr2471452vsj.176.1538662700317; Thu, 04 Oct 2018 07:18:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Mike Bayer Date: Thu, 4 Oct 2018 10:18:08 -0400 Message-ID: Subject: Re: Plans for 2.8 To: Daniele Varrazzo Cc: psycopg@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Oct 4, 2018 at 8:38 AM Daniele Varrazzo wrote: > > Hello, > > next week I will have some time and maybe could end all the work to > release psycopg 2.8. I am aware there are several features which have > been awaiting for some time. The state of the work can be seen in [1]. > > [1] https://github.com/psycopg/psycopg2/issues?q=milestone%3A"psycopg+2.8" > > Psycopg 2.8 will only support Python 2.7 and 3.4+. The codebase has > been heavily hammered by Jon Dufresne who has killed a lot of Py2isms > and the whole use of 2to3 is now replaced by a minimal compatibility > module. So Python is now as modern as C in supporting both 2 and 3 > with a single codebase :P Other deprecated and unused objects have > also been dropped, see the news file [2]. Fog, if you can take a look > at examples/sandbox and delete what's no more required there (#645), > that would be great :) > > [2] https://github.com/psycopg/psycopg2/blob/master/NEWS > > The feature I'm the most excited about (and worried about its > reception) is to raise a different exception for every postgres error > message (see #682) . For instance `SELECT * FROM wrong_name` will > raise `UndefinedTable` rather than `ProgrammingError`. Currently > handling a specific exception requires catching a broader class and > looking at the pgcode: > > try: > cur.execute("lock table %s in access exclusive mode nowait" % name) > except psycopg2.OperationalError as e: > if e.pgcode == psycopg2.errorcodes.LOCK_NOT_AVAILABLE: > locked = True > else: > raise > > This can become a much more natural: > > try: > cur.execute("lock table %s in access exclusive mode nowait" % name) > except psycopg2.errors.LockNotAvailable: > locked = True > > The error classes are generated automatically from Postgres source > code and are subclasses of the previously existing ones, so existing > code should be unaffected. I'd be happy to have input about the > feature and suggestions before releasing it. I can't provide any suggestions, as the feature is very reasonable and useful. But I will lament that pep-249 has nothing about this, which means from a driver-agnostic point of view, the situation is pretty much unchanged. Here's code I wrote for Openstack to try to apply more specificity to database errors, basically a library of regexes: https://github.com/openstack/oslo.db/blob/master/oslo_db/sqlalchemy/exc_filters.py#L55 one thing that would be helpful would be if your fine-grained exception classes included more context about the failure. Like UndefinedTable would include the table name as an individual datamember e.g. exception.table_name, an error about a foreign key constraint would include the constraint name e.g. exception.constraint_name, things like that. You can see in my oslo.db library above we are also pulling out other elements from the error message to provide more context. > > A tiny improvement to SQL generation is already ready^W merged in > #732: it will be possible to use `Identifier("schema", "name")` which > would be rendered in dotted notation in the query. Currently > `Identifier()` takes a single param so this extension is backward > compatible and there is no need to introduce a new `Composable` type > to represent dotted sequences of identifiers. > > There are requests to get extra info about the connection or the > result (see #726, #661). They are reasonable and not too difficult to > implement so I'd like to give them a go. However they are easy enough > for someone to contribute if you feel? That would be very appreciated > and would reduce the surface of the works to perform on my part. > Another tiny feature would be to support IntEnum out-of-the-box > (#591), which I've never used in Python. > > In the other thread these days we have discussed about introducing > capsules: we can take a look to that too... Added #782. > > Thank you very much for any contribution, with ideas and even more with code :) > > -- Daniele >