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

Enhances DjangoAdmin support #22

Closed

Conversation

jerinpetergeorge
Copy link
Contributor

Fixes #21 (or enhances the support for Django admin)

@ankane
Copy link
Member

ankane commented Jul 25, 2023

Hey @jerinpetergeorge, thanks for the PR! Can confirm format_value fixes the text input value. What error and stack trace are you seeing without the has_changed override?

@jerinpetergeorge
Copy link
Contributor Author

Hey @jerinpetergeorge, thanks for the PR! Can confirm format_value fixes the text input value. What error and stack trace are you seeing without the has_changed override?

Internal Server Error: /admin/polls/vector/4/change/
Traceback (most recent call last):
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/options.py", line 688, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 242, in inner
    return view(request, *args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1889, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/utils/decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1747, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1800, in _changeform_view
    change_message = self.construct_change_message(
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1186, in construct_change_message
    return construct_change_message(form, formsets, add)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/contrib/admin/utils.py", line 530, in construct_change_message
    changed_data = form.changed_data
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/jpg/.virtualenvs/generic-django-example-Kc6WXfau/lib/python3.9/site-packages/django/forms/forms.py", line 487, in changed_data
    if changed:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Vector.issue.mp4

@ankane
Copy link
Member

ankane commented Jul 27, 2023

Thanks @jerinpetergeorge, which version of Django is it?

@jerinpetergeorge
Copy link
Contributor Author

Thanks @jerinpetergeorge, which version of Django is it?

Its 4.2.x @ankane

@ankane
Copy link
Member

ankane commented Jul 27, 2023

Hmm, what's the exact version? I'm not able to reproduce, or find that stack trace in any of the 4.2.x releases.

@jerinpetergeorge
Copy link
Contributor Author

Hmm, what's the exact version? I'm not able to reproduce, or find that stack trace in any of the 4.2.x releases.

Just checked, its Django==4.2.2.

This is my complete requirements if required

amqp==5.1.1
asgiref==3.7.1
asttokens==2.2.1
async-timeout==4.0.2
attrs==23.1.0
backcall==0.2.0
billiard==3.6.4.0
black==23.3.0
cachetools==5.3.1
celery==5.2.7
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
colorama==0.4.6
coreapi==2.3.3
coreschema==0.0.4
coverage==7.2.7
cryptography==40.0.2
decorator==5.1.1
defusedxml==0.7.1
distlib==0.3.6
Django==4.2.2
django-allauth==0.54.0
django-crispy-forms==2.0
django-dbbackup==4.0.2
django-debug-toolbar==4.0.0
django-dev-superuser @ git+https://github.com/jerinpetergeorge/django-dev-superuser.git@f792f96a227116247196a26c670e58fb34712071
django-environ==0.10.0
django-extensions==3.2.1
djangorestframework==3.14.0
djangorestframework-simplejwt==5.2.2
drf-spectacular==0.26.4
drf-yasg==1.21.5
exceptiongroup==1.1.1
executing==1.2.0
factory-boy==3.2.1
Faker==18.9.0
filelock==3.12.0
flake8==6.0.0
flake8-print==5.0.0
graphql-core==3.2.3
gunicorn==20.1.0
identify==2.5.24
idna==3.4
inflection==0.5.1
iniconfig==2.0.0
ipython==8.14.0
isort==5.12.0
itypes==1.2.0
jedi==0.18.2
Jinja2==3.1.2
jsonschema==4.17.3
kombu==5.2.4
MarkupSafe==2.1.2
matplotlib-inline==0.1.6
mccabe==0.7.0
mypy-extensions==1.0.0
mysqlclient==2.1.1
nodeenv==1.8.0
numpy==1.25.1
oauthlib==3.2.2
packaging==23.1
parso==0.8.3
pathspec==0.11.1
pexpect==4.8.0
pgvector==0.1.8
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.5.1
pluggy==1.0.0
pre-commit==3.3.2
prompt-toolkit==3.0.38
psycopg2==2.9.6
ptyprocess==0.7.0
pure-eval==0.2.2
pycodestyle==2.10.0
pycparser==2.21
pyflakes==3.0.1
Pygments==2.15.1
PyJWT==2.7.0
pyproject_api==1.5.1
pyrsistent==0.19.3
pytest==7.3.1
pytest-django==4.5.2
python-dateutil==2.8.2
python3-openid==3.2.0
pytz==2023.3
PyYAML==6.0
redis==4.5.5
requests==2.31.0
requests-oauthlib==1.3.1
ruamel.yaml==0.17.26
ruamel.yaml.clib==0.2.7
six==1.16.0
sqlparse==0.4.4
stack-data==0.6.2
strawberry-graphql==0.176.4
strawberry-graphql-django==0.9.4
tomli==2.0.1
tox==4.6.0
traitlets==5.9.0
typing_extensions==4.6.1
uritemplate==4.1.1
urllib3==2.0.2
vine==5.0.0
virtualenv==20.23.0
wcwidth==0.2.6
whitenoise==5.2.0

@ethagnawl
Copy link

I also see this behavior with Django 4.2.3.

@ankane
Copy link
Member

ankane commented Aug 1, 2023

Unfortunately, I'm still not able to reproduce with a fresh Django app. Happy to include the changes without the has_changed override until that's figured out.

Could also try to reproduce with a test case. For instance, the format_value override fixes

# assert 'value="[1.0, 2.0, 3.0]"' in form.as_div()

@jerinpetergeorge
Copy link
Contributor Author

Unfortunately, I'm still not able to reproduce with a fresh Django app. Happy to include the changes without the has_changed override until that's figured out.

Could also try to reproduce with a test case. For instance, the format_value override fixes

# assert 'value="[1.0, 2.0, 3.0]"' in form.as_div()

I have made a few changes to this PR, thus, if you run the test suite against jerinpetergeorge:django-admin branch, you will get the errors. Also, all tests will be passed if you remove the this commit.

ankane pushed a commit that referenced this pull request Aug 1, 2023
@ankane
Copy link
Member

ankane commented Aug 1, 2023

Awesome, thanks @jerinpetergeorge! Squashed and pushed in 557983b.

@ankane ankane closed this Aug 1, 2023
@jerinpetergeorge jerinpetergeorge deleted the django-admin branch August 1, 2023 04:12
@ethagnawl
Copy link

I've been away for a few weeks and am just now catching up on notifications. I can confirm that the fix works. Thank you both, @ankane and @jerinpetergeorge for getting the fix in and published so quickly!

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

Successfully merging this pull request may close these issues.

Integration with Django Admin
3 participants