Re: missing required positional arguments

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.web.zope.zodb
Message-ID <20161117063544.7ra6qoyksg3gqd6d@platonas>
On Thu, Nov 17, 2016 at 03:28:24AM +0000, Boylan, Ross wrote:
> I'm having trouble pulling an instance back from the database (ZEO).  It's a revision object from hglib package.  My first try did not import hglib in the client; the second try did.  Both got the same error; see below for fuller output.
> 
> Maybe the type in the database is defined using some kind of nested class I can't easily access, maybe tng.hglib.revision?
> 
> https://selenic.com/repo/python-hglib/file/tip/hglib/client.py defines
> class revision(tuple):
>     def __new__(cls, rev, node, tags, branch, author, desc, date):
>         return tuple.__new__(cls, (rev, node, tags, branch, author, desc, date))

This class does not support pickling.  Try it:

   >>> import pickle
   >>> r = revision(1, 2, 3, 4, 5, 6, 7)
   >>> p = pickle.dumps(r)
   >>> r2 = pickle.loads(p)

The simplest way to make it pickle-compatible would be to override
revision.__getnewargs__().

> Fuller history:
> Most of my code is in a package/module tng
> In an interactive session I did
> from tng import *
> as well as importing ZEO and other stuff, but NOT hglib.
> In the session I retrieved an object from the database, called a method on it that causes the 
> revision to be set (inside my module is an import hglib), and committed.
> 
> In another session I tried to read the object I just wrote.  That session did from tng import *; as noted I tried with and without import hglib.  Here's the error from that session:
> 
> Couldn't load state for tng.Basics.BigBatch 0x044d
> Traceback (most recent call last):
>   File "/home/ross/.local/lib/python3.4/site-packages/ZODB-5.0.0-py3.4.egg/ZODB/Connection.py", line 757, in setstate
>     self._reader.setGhostState(obj, p)
>   File "/home/ross/.local/lib/python3.4/site-packages/ZODB-5.0.0-py3.4.egg/ZODB/serialize.py", line 622, in setGhostState
>     state = self.getState(pickle)
>   File "/home/ross/.local/lib/python3.4/site-packages/ZODB-5.0.0-py3.4.egg/ZODB/serialize.py", line 615, in getState
>     return unpickler.load()
> TypeError: __new__() missing 6 required positional arguments: 'node', 'tags', 'branch', 'author', 'desc', and 'date'
> [the entire error was printed twice for some reason]

This is because the inherited tuple.__getnewargs__ returns a tuple with
one argument (which is a tuple itself) that is then passed to __new__.

HTH,
Marius Gedminas
-- 
There are 10 kinds of people in the world: Those who understand binary
mathematics and those who don't.

-- 
You received this message because you are subscribed to the Google Groups "zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
signature.asc (application/pgp-signature, 163 B)
-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAlgtT70ACgkQkVdEXeem149kogCfcr14DvIl86lhZh6oiR8sJuuI
S5kAn0uRh9N/XWB0Fat5pdQcA89V0MG3
=cLS+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.