New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: '_UnpickleDispatch' object has no attribute '__name__' #180

Closed
russlamb opened this Issue Sep 3, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@russlamb
Copy link

russlamb commented Sep 3, 2017

trying to use this module with sqlalchemy, similar to #99 but it doesn't seem to work. I saw the commit related to this issue and the related test. my code seems similar. Is there something I'm missing?

module versions:
jsonpickle==0.9.5
SQLAlchemy==1.1.6

Python 3.5.2 :: Anaconda custom (x86_64)


import sqlalchemy as sa, json
import jsonpickle as jp

def main():

    meta = sa.MetaData()
    t = sa.Table("test",meta,
        sa.Column("id",sa.Integer())
    )
    engine=sa.create_engine("sqlite:///:memory:")
    meta.create_all(engine)

    t_json = (jp.encode(t))

if __name__=="__main__":
    main()


errors:
  File "/Users/yomamma/Dropbox/Coding/Python/SqlTesting/db_test.py", line 17, in main
    t_json = (jp.encode(t))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/__init__.py", line 132, in encode
    numeric_keys=numeric_keys)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 43, in encode
    return backend.encode(context.flatten(value, reset=reset))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 156, in flatten
    return self._flatten(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 160, in _flatten
    return self._pop(self._flatten_obj(obj))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 234, in _ref_obj_instance
    return self._flatten_obj_instance(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 375, in _flatten_obj_instance
    return self._getstate(state, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 523, in _getstate
    state = self._flatten_obj(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 433, in _flatten_dict_obj
    flatten(k, v, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 502, in _flatten_key_value_pair
    data[k] = self._flatten(v)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 160, in _flatten
    return self._pop(self._flatten_obj(obj))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 234, in _ref_obj_instance
    return self._flatten_obj_instance(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 375, in _flatten_obj_instance
    return self._getstate(state, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 523, in _getstate
    state = self._flatten_obj(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 433, in _flatten_dict_obj
    flatten(k, v, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 502, in _flatten_key_value_pair
    data[k] = self._flatten(v)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 160, in _flatten
    return self._pop(self._flatten_obj(obj))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 179, in _list_recurse
    return [self._flatten(v) for v in obj]
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 179, in <listcomp>
    return [self._flatten(v) for v in obj]
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 160, in _flatten
    return self._pop(self._flatten_obj(obj))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 234, in _ref_obj_instance
    return self._flatten_obj_instance(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 375, in _flatten_obj_instance
    return self._getstate(state, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 523, in _getstate
    state = self._flatten_obj(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 433, in _flatten_dict_obj
    flatten(k, v, data)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 502, in _flatten_key_value_pair
    data[k] = self._flatten(v)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 160, in _flatten
    return self._pop(self._flatten_obj(obj))
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 176, in _flatten_obj
    return flatten_func(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 234, in _ref_obj_instance
    return self._flatten_obj_instance(obj)
  File "/Users/yomamma/anaconda/envs/p3.5/lib/python3.5/site-packages/jsonpickle/pickler.py", line 331, in _flatten_obj_instance
    if rv_as_list[0].__name__ == '__newobj__':
AttributeError: '_UnpickleDispatch' object has no attribute '__name__'

@davvid davvid closed this in 5aba54b Sep 4, 2017

davvid added a commit that referenced this issue Sep 4, 2017

doc: mention #180 in the changelog
Signed-off-by: David Aguilar <davvid@gmail.com>

davvid added a commit that referenced this issue Sep 4, 2017

Merge branch 'sqlalchemy'
* sqlalchemy:
  doc: mention #180 in the changelog
  jsonpickle: better support for dynamic SQLAlchemy Table objects

Closes #180
Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid

This comment has been minimized.

Copy link
Member

davvid commented Sep 4, 2017

I added this exact use case to the test suite and got it working. Thanks for the heads-up. There are caveats about adding objects to an existing sqlalchemy session (since they'll probably create new rows!) but read-only usage should work. For reference see tests/sqlalchemy_test.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment