Openskin: calculation stops with error if kVp is missing

Issue #558 resolved
Luuk created an issue

If kVp is missing the calculation the raised exception isn't caught and will crash.

This might be the case for more parameters.

Suggestion for change in the case of kVp. In make_skin_map in make_skin_map.py change:

            if irrad.irradeventxraysourcedata_set.get().kvp_set.get().kvp:
                kvp = float(irrad.irradeventxraysourcedata_set.get().kvp_set.get().kvp)
            else:
                kvp = None

to

            if irrad.irradeventxraysourcedata_set.get().kvp_set.exists() and \
               irrad.irradeventxraysourcedata_set.get().kvp_set.get().kvp:
                kvp = float(irrad.irradeventxraysourcedata_set.get().kvp_set.get().kvp)
            else:
                kvp = None

Comments (6)

  1. Ed McDonagh

    My preferred approach to these things now is to do the thing within a try, then catch the ObjectDoesNotExist for the alternative.

  2. Ed McDonagh

    Do you have sample data with missing kV so we can throw some tests in to ensure it stays fixed once fixed?

  3. Luuk reporter

    Refs #558 Openskin: calculation stops with error if kVp is missing

    Implemented try / except blocks around multiple parameters Not only ObjectDoesNotExist, but for the parameters converted to float also TypeError

    Test file added.

    → <<cset b49b1204e8b1>>

  4. Ed McDonagh

    Merged in Issue558SkinMapStopsOnNoKvp (pull request #127)

    Fixes #558 Openskin: calculation stops with error if kVp is missing

    I'd like to see further changes to this code as per ref #563, but this PR is better than the current code for several reasons so we'll merge this in :-)

    → <<cset 6559337e3596>>

  5. Log in to comment