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

Error creating new Project/Task #155

Open
Joao-oliveiraf opened this issue Feb 7, 2025 · 1 comment
Open

Error creating new Project/Task #155

Joao-oliveiraf opened this issue Feb 7, 2025 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Joao-oliveiraf
Copy link

Hi! I've been trying to use the Tasks feature to create new Projects and I was getting this error:

Image
The error happens on the method below, on tasks/site/tasksbasemodeladmin.py

def save_model(self, request, obj, form, change):
        if "next_step" in form.changed_data:
            if obj.responsible.count() == 1 and obj.responsible.get() != request.user:
                obj.next_step += f" ({request.user})"
            obj.add_to_workflow(f'{obj.next_step}.')

        if "next_step_date" in form.changed_data:
            if (
                    all((obj.next_step_date, obj.due_date))
                    and obj.next_step_date > obj.due_date
            ):
                html_msg = (
                    get_trans_for_user(NEXT_STEP_DATE_WARNING, request.user)
                    + f'<a href="{obj.get_absolute_url()}"> {obj.name}  ({obj.owner})</a>'
                )
                save_message(request.user, html_msg, "INFO")

        super().save_model(request, obj, form, change)

From what I gather, when entering the very first if check, the logic within tries to perform a relational operation of this object with another, but this object we are trying to save doenst quite exists yet, so we cannot access it's "ID" field.

I've created a workaround setting the model to allow blank values, this way I can avoid this condition altogether

    next_step = models.CharField(
        max_length=250,
        verbose_name=_("Next step"),
        help_text=_("Describe briefly what needs to be done in the next step."),
        blank=True,
    )

After making the migrations Project creation was working and the "next step" was defaulting to "Acquainted with the project"

Image

Hope that this helps somehow!

@DjangoCRM
Copy link
Owner

Thanks for reporting.
The error occurred in the code execution flow of the admin site, which is different from the CRM site.
Typically, projects are created by users on the CRM website. In this case, the fields next_step and next_step_date are not added to the form (but filled in automatically). Therefore, the error does not occur.
Since filling in the fields next_step and next_step_date is important for teamwork, it is better to also exclude adding these fields to the form on the admin site when creating a project (to have them filled in automatically).
This can be done in method tasks.admin.ProjectAdmin.get_fieldsets().

@DjangoCRM DjangoCRM added bug Something isn't working good first issue Good for newcomers labels Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Todo
Development

No branches or pull requests

2 participants