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

Remove hardcoding + form duplication copies changes to default fields #19

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

iiloni-umd
Copy link
Collaborator

What's this PR do?

Changes all queue and form object creation to use input dictionaries instead of destructuring and restructuring of objects with hard-coded keys.

When should it be merged in?

As soon as it's ready

Do you want someone to review this before it gets merged in?

Yes, I just want to make sure that my changes reflect the appropriate way to handle object creation.

How should this be manually tested?

Use the queue and form management pages in the system settings of helpdesk.

@iiloni-umd iiloni-umd added the bug Something isn't working label Aug 26, 2024
@iiloni-umd iiloni-umd self-assigned this Aug 26, 2024
@ebeers-png
Copy link
Collaborator

When I try saving a form (after either deleting a field or doing nothing to any of the fields), I get this error:

Traceback (most recent call last):
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/elizabeth/Github/django-helpdesk/helpdesk/views/staff.py", line 390, in edit_form
    CustomField.objects.filter(id=customfield.id).update(**cf)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/query.py", line 783, in update
    rows = query.get_compiler(self.db).execute_sql(CURSOR)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1162, in execute_sql
    sql, params = self.as_sql()
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1515, in as_sql
    val.prepare_database_save(field),
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/base.py", line 1010, in prepare_database_save
    raise ValueError("Unsaved model instance %r cannot be used in an ORM query." % self)

Exception Type: ValueError at /helpdesk/system_settings/maintain_forms/1/edit/
Exception Value: Unsaved model instance <FormType: FormType - None None> cannot be used in an ORM query.

Error from creating a new form (I set the name and the queue and changed nothing else from the default):

Traceback (most recent call last):
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)

The above exception (invalid literal for int() with base 10: '') was the direct cause of the following exception:
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/elizabeth/Github/django-helpdesk/helpdesk/views/staff.py", line 319, in create_form
    formtype = get_object_or_404(FormType, pk=request.POST.get('id'))
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/shortcuts.py", line 76, in get_object_or_404
    return queryset.get(*args, **kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/query.py", line 424, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/query.py", line 941, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1416, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1435, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1370, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1216, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/lookups.py", line 25, in __init__
    self.rhs = self.get_prep_lookup()
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/lookups.py", line 77, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/home/elizabeth/.pyenv/versions/beam2.19.0/lib/python3.9/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(

Exception Type: ValueError at /helpdesk/system_settings/maintain_forms/create/
Exception Value: Field 'id' expected a number but got ''.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants