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

Fix get_field_value #71

Open
moshthepitt opened this issue Aug 22, 2020 · 0 comments
Open

Fix get_field_value #71

moshthepitt opened this issue Aug 22, 2020 · 0 comments

Comments

@moshthepitt
Copy link
Owner

get_field_value will throw an error is the field is not hashable. e.g. for JSON field

Suggested fix:

    def get_field_value(self, field):
        """Get the value of a field."""
        if field.is_relation:
            try:
                return str(getattr(self.object, field.name))
            except AttributeError:
                return None
        try:
            # pylint: disable=protected-access
            return self.object._get_FIELD_display(field)
        except TypeError:
            # for some reason this is not hashable
            field_value = getattr(self.object, field.attname)
            return json.dumps(field_value, cls=DjangoJSONEncoder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant