Skip to content
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

CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj' #74

Closed
aclark4life opened this issue Dec 28, 2017 · 8 comments

Comments

@aclark4life
Copy link

When trying to dumpdata with a model that uses multiselectfield in Django 2.0 I get this … is this me doing something wrong or something to do with multiselectfield? Thanks for any insight and for multiselectfield!

@blag
Copy link
Collaborator

blag commented Dec 28, 2017

This project doesn't support Django 2.0+ yet. I'll happily accept PRs for it though.

This project is also a dirty hack - if you will ever do any filtering on the MultiSelectField you will want to use Django's full many to many relation instead.

I'll leave this issue open until the project is compatible with Django 2.0. Thanks!

@CodyBontecou
Copy link

CodyBontecou commented Jan 26, 2018

What would be the first steps to making this compatible with Django 2.0? I'm happy to do some research and help where I can. The error I am getting starts with CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj' yet when I google "Django 2.0 _get_val_from_obj", it looks like it's been deprecated in Django 2.0.

@brathis
Copy link

brathis commented Jan 28, 2018

@CodyBontecou to make it work with Django 2.0 you can simply change one line in multiselectfield/db/fields.py
Change line 105 from value = self._get_val_from_obj(obj) to value = self.value_from_object(obj)
Then it should work just fine (at least dumpdata works for me again)

@blag blag mentioned this issue Jan 29, 2018
@blag
Copy link
Collaborator

blag commented Jan 29, 2018

I've started a branch and PR for Django 2.0 compatibility: #77. It's currently running into issues and I don't have time to debug all of it right now. Help wanted.

@blag blag added the bug label Jan 29, 2018
@scientifichackers
Copy link

@brathis, Thanks, it also makes jsonify work

@koddr
Copy link

koddr commented May 22, 2018

Is this bug still live?

I use master branch version (0.1.8) on Django 2.0.5, but have CommandError: Unable to serialize database: 'MultiSelectField' object has no attribute '_get_val_from_obj' after use ./manage.py dumpdata ... command.

Way to solve it?

laowantong added a commit to laowantong/django-multiselectfield that referenced this issue Sep 1, 2018
@bjornuppeke
Copy link

bjornuppeke commented Sep 24, 2018

If you just want to fix this particular issue in Django >2.0 before the PR is merged and still want a clean env, create a new class:

from multiselectfield import MultiSelectField

class PatchedMultiSelectField(MultiSelectField):
  def value_to_string(self, obj):
    value = self.value_from_object(obj)
    return self.get_prep_value(value)

and use that in your model.

@wfehr
Copy link

wfehr commented Nov 6, 2019

I think this can be closed as the changes of #99 are already released with v0.1.10?

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

Successfully merging a pull request may close this issue.

7 participants