Skip to content

Switch ZendeskForm to ModelForm#7265

Open
denyshon wants to merge 1 commit into
mozilla:mainfrom
denyshon:zendeskfrom-to-modelform
Open

Switch ZendeskForm to ModelForm#7265
denyshon wants to merge 1 commit into
mozilla:mainfrom
denyshon:zendeskfrom-to-modelform

Conversation

@denyshon

@denyshon denyshon commented Feb 19, 2026

Copy link
Copy Markdown
Contributor
  • Switch ZendeskForm from Form to ModelForm to benefit from model validation.
  • Specify SupportTicket.description max_length based on the Zendesk API.
  • Set blank=True for SupportTicket.category to prevent a model validation error in case we decide to make this field optional.
  • Adjust kitsune.customercare.tests.test_forms.ZendeskFormTests.test_send_with_no_category_selected to ignore a form validation error.

Resolves #2806.

@denyshon denyshon force-pushed the zendeskfrom-to-modelform branch 4 times, most recently from 731da2d to 5a3a57e Compare February 21, 2026 15:32

@akatsoulas akatsoulas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @denyshon for the PR! I added a couple of comment

Comment thread kitsune/customercare/tests/test_forms.py
@denyshon denyshon force-pushed the zendeskfrom-to-modelform branch 2 times, most recently from 6c2d272 to 7f286c9 Compare March 6, 2026 22:42
@denyshon

denyshon commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@akatsoulas Thank you for the review! I've replied to your comment and rebased the patch onto the latest main.

@denyshon denyshon force-pushed the zendeskfrom-to-modelform branch from 7f286c9 to 410e1ec Compare July 7, 2026 08:33
description = models.TextField()
category = models.CharField(max_length=255)
description = models.TextField(max_length=65563)
category = models.CharField(max_length=255, blank=True, default="")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the form does not allow an empty value, I would argue that the model shouldn't allow this as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this change will also need a schema migration

@denyshon denyshon Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

form does allow an empty value: category=self.cleaned_data.get("category", "")
in case we'll unmark the field as required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a handwritten migration, but from what I understand, it should ideally be generated by django?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(updated the comment above, the current behavior regarding an empty value is not consistent, so you'll be the best person to decide on this)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can run ./manage.py makemigrations to create the migration and ./manage migrate to apply it

Comment thread kitsune/customercare/models.py Outdated
subject = models.CharField(max_length=255)
description = models.TextField()
category = models.CharField(max_length=255)
description = models.TextField(max_length=65563)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the value be 65535?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I took that value from the docs, but now they say just "64 kB", so let me make change this to 65535

}
# An empty category field will result in a form validation error in send()->save().
# Since we don't care about the form, we'll just clear the errors to run send().
form._errors = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why we are bypassing the form errors here. We shouldn't be able to send() given the invalid form

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can pass a random topic if you want

Switch ZendeskForm from Form to ModelForm to benefit from model validation.
Specify SupportTicket.description max_length based on the Zendesk API.
Set blank=True for SupportTicket.category to prevent a model validation error in case we decide to make this field optional.
Adjust kitsune.customercare.tests.test_forms.ZendeskFormTests.test_send_with_no_category_selected to ignore a form validation error.
@denyshon denyshon force-pushed the zendeskfrom-to-modelform branch from 410e1ec to 189f314 Compare July 9, 2026 12:56
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

Successfully merging this pull request may close these issues.

500 error message when trying to submit a ticket with a long subject for a premium product

2 participants