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

Attempting to implement conditional views generates the error RecursionError: maximum recursion depth exceeded #264

Open
ghost opened this issue Jan 18, 2024 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 18, 2024

Hello! I'm trying to implement Django Wizard's conditional view in my project but I can't. Whenever I access my form page, I receive the error: RecursionError: maximum recursion depth exceeded
.

I investigated what is generating this error with ipdb and found that the WizardView.get_cleaned_data_for_step(step) method

is causing the problem.

I would like help to know if I implemented the feature correctly or if this is a bug.

NT. I want it to work as follows:

In the PessoaForm form there is a checkbox field where my user must select one of two options: PF or PJ. If he selects PF then the next form displayed should be the PessoaFisicaForm and if he selects the PJ option, then the PessoaJuridicaForm form should be displayed.

These are my forms

Screenshot from 2024-01-18 15-40-35

This is my view
Screenshot from 2024-01-18 15-41-33

and this is the callable that you create according to the documentation guidance

Screenshot from 2024-01-18 15-41-56

Error generated

Screenshot from 2024-01-18 16-11-22

@pfouque
Copy link
Member

pfouque commented Feb 14, 2024

Hi,
I faced a similar issue and ended up declaring the form_list with explicit naming:

class MyWizard(SessionWizardView):
    form_list: list[tuple[str, type[Form]]] = [
        ("pessoa", PessoaForm),
        ("fisica", PessoaFisicaForm),
        ("juridica", PessoaJuridicaForm),
    ]
    
    @staticmethod
    def show_fisica(wizard: SessionWizardView) -> bool:
        if pessoa_data := wizard.get_cleaned_data_for_step("pessoa"):
            return pessoa_data.get("tipo") == "fisica"
        return False

    @staticmethod
    def show_juridica(wizard: SessionWizardView) -> bool:
        if pessoa_data := wizard.get_cleaned_data_for_step("pessoa"):
            return pessoa_data.get("tipo") == "juridica":
                return company is None
        return True

    condition_dict = {
        "fisica": show_fisica,
        "juridica": show_juridica,
    }

Maybe it will work for you too...
or you could try switching only the Form instead (by overriding get_form)

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