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
Upgrading from 1.6.1 to 1.7.* - forms don't work #848
Comments
I checked and it also doesn't work properly with versions 1.7.0 and 1.7.1. |
Hi @uri-rodberg. Curious one. Are you able to bisect the issue to a particular change? (It's not initially obvious what might be the issue...) |
I having the same issue , and I asked it on https://stackoverflow.com/questions/54101476/crispy-forms-and-bootstrap-styles?noredirect=1#comment95058861_54101476 and I hope any one could help me with it |
Which versions of django-crispy-forms did you try using and did it work with any of them? |
It's a change in django-crispy-forms and not in our code. Our same code works with |
If you can put it in a test case we (you?) can use Very happy to look at it, but need a failing example... |
I've just instaleed it today, by pip install --upgrade django-crispy-forms |
I created a test that checks it - you can see it on https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/feedback/tests/test_views.py. If you run tests with Compare https://travis-ci.org/speedy-net/speedy-net/builds/477445100 and https://travis-ci.org/speedy-net/speedy-net/builds/477451490 You can run tests with You can compare https://travis-ci.org/speedy-net/speedy-net/builds/477460948 and https://travis-ci.org/speedy-net/speedy-net/builds/477460938. @carltongibson Did I answer your question? |
Check with 1.6.1 and let me know if it works. I'm not sure it's related to the same issue I posted. |
it gives me error in th cmd :
|
and if I imported : in the forms.py it will yield another error :
|
@mostafagafer Why do you think it's related to this issue? |
@uri-rodberg. Can you clone the repo then Checkout a failing commit then run Here's the top google hit for "Django git bisect". It looks good: https://alexlouden.com/posts/2016-git-bisect-django-unit-tests/ |
@carltongibson I will try. By the way, I see I upgraded django-crispy-forms to 1.7.2 six months ago (on June 27 - speedy-net/speedy-net@91a0f9f) but tests didn't fail so I was not aware of this bug. I added the tests today which fail when this bug exists. |
@mostafagafer The line causing your error was changed in #681 and was part of v1.7. Your issue is unrelated to the current topic. I advise you run |
|
http://pip.pypa.io/en/stable/reference/pip_install/ see “Editable Installs”. You’ll need to have your virtualenv activated. Then the If you paste the error I may be able to assist. (But it should just install) |
OK, I didn't understand you want me to clone your repository. I did it and got the following output: ImportError: cannot import name 'memoize'
:040000 040000 5dc0ff513afbce82db9e0ef5573b94b5de1ce6c5 d046dfde517fcadf347cf9821c6a15923a404411 M crispy_forms But I'm not sure how it is related to a commit from 2015. |
I found out what I can change to make this work:
If I change the 2 ifs to True then it works. Did I miss anything in the settings? |
I checked your code and the following if (lines 342 to 348 in
It looks to me that it's not necessary since the fields in You can see our code on https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/feedback/forms.py and the fields defined in |
So what's different here? What about logging-in changes how the conditional evaluates? How is that something to do with Crispy Forms? (It may be that it is, but I'm not quite seeing it yet...) |
@carltongibson I don't understand, what do you want me to do? Is it a bug in django-crispy-forms or is it the expected behavior? I downgraded Speedy Net to |
I'm trying to understand why the issue arrises. From there we can decide if it's a bug or expected behaviour, and fix it accordingly (either in your project code or here). Why the issue doesn't occur when the user is logged in is strange. So what's going on there? (If we can explain that then we'll have our answer I think.) |
@carltongibson Thanks for the explanation. I don't know the reason, but you can see from the tests with 1.7.2 [https://travis-ci.org/speedy-net/speedy-net/builds/477460938], that |
Maybe the difference is in the following code:
https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/feedback/forms.py Maybe we must set https://stackoverflow.com/questions/11010662/django-crispy-forms-layout-div |
@carltongibson Any comments? Is it a bug in django-crispy-forms or is it the expected behavior? Did we do something wrong in Speedy Net in the way we used django-crispy-forms? |
Sorry @uri-rodberg, still not at all sure why it's working with an authenticated user and not without? We don't really have time to dig through the Speedy Net code to see what's going on there. If you can reduce it to a minimal example it would be possible to comment. Ideally you'd present a minimal unit test showing behaviour that you expect to work but is not. |
@carltongibson
This is the main difference between the feedback form for an authenticated user and the feedback form for a non-authenticated user. Notice we have |
OK, I confirmed with a commit now that if you comment these lines the tests pass and the form contains all the fields we want, but the HTML design is not what we want (because these lines sets the HTML design we want). You can see https://travis-ci.org/speedy-net/speedy-net/builds/485932345 and https://github.com/speedy-net/speedy-net/blob/uri_merge_with_master_2019-01-08_b_copy_with_django-crispy-forms_1.7.2/speedy/core/feedback/forms.py. |
A minimal example is one using just Django + Crispy Forms. Preferably it would be in the form of a PR including a test case to the project. Failing that a minimal project based on In particular the I'm happy to look at a minimal example but we simply don't have the capacity to look through your project code to work out what's going on. |
- Instead of using FormHelper() directly, use FormHelperWithDefaults() where render_unmentioned_fields = True. [django-crispy-forms/django-crispy-forms#848] - TODO: check if forms will not contain unnecessary fields because of this change.
@carltongibson It takes time and I don't have much time now to setup a minimal example as you defined. In the meantime I changed the code in Speedy Net so that |
OK, glad you found a workaround. I'm going to close pending a reproduce. If you come up with one, happy to reopen then. |
I would like to reopen this issue. It's very easy to reproduce for me. Let's have a ModelForm and add a few custom fields to it
If you render this form in Crispy Forms < 1.7.0 it works and renders both fields The reason is commit 6b93e8a which broke it.
I wonder why @ghinch committed this at all. If fields are mentioned in Meta.fields they should be unconditionally rendered, shouldn't they? |
Actually, it's even worse than I thought. Setting render_unmentioned_fields to True causes all fields rendered through the block above the mentioned code where the fields are defined as a set(form.fields.keys()) which is unordered so the form looks differently (fields are randomly ordered). |
@carltongibson Do you want to comment on what @naro wrote? |
Ok yep. Let’s reopen to have a look. Thanks @naro. |
Did PR #952 fix this issue? Maybe it's time to close this issue? @naro @carltongibson |
Hi @uri-rodberg. Good follow-up. If it's fixed for you in current We're rolling 1.9 soon™ |
Description:
We upgraded Speedy Net from
django-crispy-forms==1.6.1
todjango-crispy-forms==1.7.2
We didn't expect anything to change.
Our contact form stopped working in all 4 websites.
Preferably also include:
The tag is
{% crispy form %}
on feedback_form.htmlScreenshots
With
django-crispy-forms==1.6.1
:With
django-crispy-forms==1.7.2
:There is no
<textarea ...
in the HTML with 1.7.0 up to 1.7.2.There is
<textarea ...
in the HTML with 1.6.1.I can't paste HTML into this issue, I tried.
The text was updated successfully, but these errors were encountered: