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

Creating file config skip filed issue #72

Closed
upsonp opened this issue Feb 7, 2024 · 1 comment
Closed

Creating file config skip filed issue #72

upsonp opened this issue Feb 7, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@upsonp
Copy link
Collaborator

upsonp commented Feb 7, 2024

I was creating a new sample configuration for a CHL file. I entered '18' in the header filed and got a 'something went wrong' message.

Stack trace:

Traceback (most recent call last):
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\asgiref\sync.py", line 534, in thread_handler
    raise exc_info[1]
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\django\core\handlers\exception.py", line 42, in inner
    response = await get_response(request)
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\django\core\handlers\base.py", line 253, in _get_response_async
    response = await wrapped_callback(
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\asgiref\sync.py", line 479, in __call__
    ret: _R = await loop.run_in_executor(
  File "C:\Program Files\Python310\lib\asyncio\futures.py", line 285, in __await__
    yield self  # This tells Task to wait for completion.
  File "C:\Program Files\Python310\lib\asyncio\tasks.py", line 304, in __wakeup
    future.result()
  File "C:\Program Files\Python310\lib\asyncio\futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\asgiref\current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Gov\Projects\djangoProject\dart\dart_env\lib\site-packages\asgiref\sync.py", line 538, in thread_handler
    return func(*args, **kwargs)
  File "C:\Gov\Projects\djangoProject\dart\core\form_sample_type_config.py", line 379, in new_sample_config
    skip = int(request.POST['skip']) if 'skip' in request.POST else -1
ValueError: invalid literal for int() with base 10: ''

based on this, I think the issue is request.POST['skip'] had some value in it that couldn't be cast to an int.

@upsonp upsonp added the bug Something isn't working label Feb 7, 2024
@upsonp
Copy link
Collaborator Author

upsonp commented Feb 7, 2024

This can sort of be reproduced if the field is blank.

Click in the filed, press backspace or delete to clear the value, wait one second.

Add a check to make sure request.POST is not '' before trying to cast it

In fact, anywhere code looks like this:

            skip = int(request.POST['skip']) if 'skip' in request.POST else -1

should probably look like this:

           skip = int(request.POST.get('skip', -1) or -1)

if the post value is not set at all, -1 will be used as the default. If the post value is '', then it's interpreted as a NoneType and -1 is returned.

@upsonp upsonp added this to the 3.1.x release milestone Feb 7, 2024
upsonp added a commit that referenced this issue Feb 8, 2024
fixed #72 for the sample and plankton loading forms
@upsonp upsonp closed this as completed Feb 8, 2024
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

No branches or pull requests

1 participant