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

Randomly failing test (test_list_worker_slot_warning) #3336

Closed
CasperWA opened this issue Sep 24, 2019 · 2 comments · Fixed by #3628
Closed

Randomly failing test (test_list_worker_slot_warning) #3336

CasperWA opened this issue Sep 24, 2019 · 2 comments · Fixed by #3628

Comments

@CasperWA
Copy link
Contributor

This was seen failing on Travis for Python3.6 when running tests using the django backend.

It was a PR that only touches the documentation (#3335).

Error:

======================================================================
FAIL: test_list_worker_slot_warning (aiida.backends.tests.cmdline.commands.test_process.TestVerdiProcessListWarning)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/aiidateam/aiida-core/aiida/backends/tests/cmdline/commands/test_process.py", line 414, in test_list_worker_slot_warning
    self.assertClickResultNoException(result)
  File "/home/travis/build/aiidateam/aiida-core/aiida/backends/testbase.py", line 201, in assertClickResultNoException
    self.assertIsNone(cli_result.exception, ''.join(traceback.format_exception(*cli_result.exc_info)))
AssertionError: TypeError('Parser must be a string or character stream, not NoneType',) is not None : Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/click/testing.py", line 326, in invoke
    cli.main(args=args or (), prog_name=prog_name, **extra)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/travis/build/aiidateam/aiida-core/aiida/cmdline/utils/decorators.py", line 68, in wrapper
    return wrapped(*args, **kwargs)
  File "/home/travis/build/aiidateam/aiida-core/aiida/cmdline/commands/cmd_process.py", line 82, in process_list
    print_last_process_state_change()
  File "/home/travis/build/aiidateam/aiida-core/aiida/cmdline/utils/common.py", line 68, in print_last_process_state_change
    timestamp = get_process_state_change_timestamp(process_type)
  File "/home/travis/build/aiidateam/aiida-core/aiida/engine/utils.py", line 301, in get_process_state_change_timestamp
    timestamps.append(timezone.isoformat_to_datetime(manager.get(key).value))
  File "/home/travis/build/aiidateam/aiida-core/aiida/common/timezone.py", line 129, in isoformat_to_datetime
    return dateutil.parser.parse(value)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 1358, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 646, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 722, in _parse
    l = _timelex.split(timestr)         # Splits the timestr into tokens
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 207, in split
    return list(cls(s))
  File "/home/travis/virtualenv/python3.6.3/lib/python3.6/site-packages/dateutil/parser/_parser.py", line 76, in __init__
    '{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not NoneType
@sphuber
Copy link
Contributor

sphuber commented Sep 25, 2019

Most likely related or duplicate of #3051

@giovannipizzi
Copy link
Member

giovannipizzi commented Dec 10, 2019

Most likely related or duplicate of #3051

I'm not sure it's a duplicate.

Instead, I got the same error as the one reported above.
The issue is that here:

timestamp = get_process_state_change_timestamp(process_type)
if timestamp is None:
echo_info('last time an entry changed state: never')
else:
timedelta = timezone.delta(timestamp, timezone.now())

We are checking in line 67 if the result is None, but the exception is raised inside line 65.
The reason is that we are calling directly timezone.isoformat_to_datetime on a value that might potentially be empty:
timestamps.append(timezone.isoformat_to_datetime(manager.get(key).value))

The fix is to to make sure that the utility to convert from isoformat to datetime timezone.isoformat_to_datetime (and back) return None if None is passed as input

giovannipizzi added a commit to giovannipizzi/aiida-core that referenced this issue Dec 10, 2019
The functions `datetime_to_isoformat` and `isoformat_to_datetime`
assumed to always have a proper type (string or datetime) as input.
However, in some cases, they were called with values that could
be potentially `None`, like this in aiida/engine/utils.py:
```
timezone.isoformat_to_datetime(manager.get(key).value))
```
We are now directly returning `None` if `None` is passed as an
input (and then it's up to the caller to then decide what to do
with the value.

Fixes aiidateam#3336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants