dict_keys issue with python-3.7

210 views
Skip to first unread message

Alexis PRAYEZ

unread,
Jun 21, 2019, 4:04:22 AM6/21/19
to MongoEngine Users
Hi folks,

I know python-3.7 is not officially supported, but the readme says to report issues with python>3.6 so here I am !
We are running our automated tests on python-2.7.15 and  python-3.7.2 and never had any issue until now.

We recently upgraded from mongoengine-0.16.2 to mongoengine-0.18.1 and we started seeing the following errors

[gw3] win32 -- Python 3.7.2 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[...]

    def __init__(self, *args, **values):
        """
        Initialise a document or an embedded document.
    
        :param dict values: A dictionary of keys and values for the document.
            It may contain additional reserved keywords, e.g. "__auto_convert".
        :param bool __auto_convert: If True, supplied values will be converted
            to Python-type values via each field's `to_python` method.
        :param set __only_fields: A set of fields that have been loaded for
            this document. Empty if all fields have been loaded.
        :param bool _created: Indicates whether this is a brand new document
            or whether it's already been persisted before. Defaults to true.
        """
        self._initialised = False
        self._created = True
    
        if args:
            # Combine positional arguments with named arguments.
            # We only want named arguments.
            field = iter(self._fields_ordered)
            # If its an automatic id field then skip to the first defined field
            if getattr(self, '_auto_id_field', False):
                next(field)
            for value in args:
                name = next(field)
                if name in values:
                    raise TypeError(
                        'Multiple values for keyword argument "%s"' % name)
                values[name] = value
    
        __auto_convert = values.pop('__auto_convert', True)
    
        __only_fields = set(values.pop('__only_fields', values))
    
        _created = values.pop('_created', True)
    
        signals.pre_init.send(self.__class__, document=self, values=values)
    
        # Check if there are undefined fields supplied to the constructor,
        # if so raise an Exception.
        if not self._dynamic and (self._meta.get('strict', True) or _created):
            _undefined_fields = set(values.keys()) - set(
>               self._fields.keys() + ['id', 'pk', '_cls', '_text_score'])
E           TypeError: unsupported operand type(s) for +: 'dict_keys' and 'list'

[...]\0.18.1\python\mongoengine\base\document.py:88: TypeError





[gw0] win32 -- Python 3.7.2 

[...]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[...]
[...]\0.18.1\python\mongoengine\document.py:712: in reload
    **self._object_key).only(*fields).limit(
[...]\0.18.1\python\mongoengine\queryset\base.py:919: in only
    return self.fields(True, **fields)
[...]\0.18.1\python\mongoengine\queryset\base.py:989: in fields
    queryset = self.clone()
[...]\0.18.1\python\mongoengine\queryset\base.py:734: in clone
    return self._clone_into(self.__class__(self._document, self._collection_obj))
[...]\0.18.1\python\mongoengine\queryset\base.py:755: in _clone_into
    setattr(new_qs, prop, copy.copy(val))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

x = dict_keys(['versions'])

    def copy(x):
        """Shallow copy operation on arbitrary Python objects.
    
        See the module's __doc__ string for more info.
        """
    
        cls = type(x)
    
        copier = _copy_dispatch.get(cls)
        if copier:
            return copier(x)
    
        try:
            issc = issubclass(cls, type)
        except TypeError: # cls is not a class
            issc = False
        if issc:
            # treat it as a regular class:
            return _copy_immutable(x)
    
        copier = getattr(cls, "__copy__", None)
        if copier:
            return copier(x)
    
        reductor = dispatch_table.get(cls)
        if reductor:
            rv = reductor(x)
        else:
            reductor = getattr(x, "__reduce_ex__", None)
            if reductor:
>               rv = reductor(4)
E               TypeError: can't pickle dict_keys objects

[...]\python\3.7\Lib\copy.py:96: TypeError


Both relates to the change of dict.keys() returning a view object 

Can you confirm this issue ?
Should I open one, two or as many issues as there are instances of this errror I encounter, or one global issue ?

Cheers,
Alexis

Reply all
Reply to author
Forward
0 new messages