You want to test if step.followupsteps
is boolean true instead:
'followupsteps': [] if not step.followupsteps else [{
'id': stepid,
} for stepid in step.followupsteps.split(',')]
You are instead testing if not None
is True, which it just so happens to be:
>>> bool(not None)
True
not step.followupsteps
is going to be True if it is an empty string, None
, numeric 0 or an empty container. You could also use if step.followupsteps is None
but why limit yourself.
Another way of spelling this:
'followupsteps': [{
'id': stepid,
} for stepid in (step.followupsteps.split(',') if step.followupsteps else [])]
but by just returning an empty list first you avoid the empty list comprehension altogether.