Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Fix bugs in required and excluded routes #18

Merged
merged 1 commit into from
Nov 6, 2014

Conversation

murphyke
Copy link
Member

@murphyke murphyke commented Nov 5, 2014

It is now an error to specify more than one required route with the
same target (ValueError is raised).

It is now possible to define multiple excluded routes involving the
same target model. Previously, the last defined exclusion route for
a target model would silently replace any other such routes.

The ModelTree _required_routes and _excluded_routes fields, which
used to be dicts keyed on target model, are now dicts keyed on
(source, target) tuple, and the value of the dict is the join field, or None
if there is no join field specified. _required_join_fields and
_excluded_join_fields are no longer needed. The code is simpler, but
lookup of a target in the excluded routes dict is less efficient now.
I expect that doesn't matter much, but if it does, we can change
to keying on target, with the value being a list of source:field tuples.

Signed-off-by: Kevin Murphy murphyke@email.chop.edu

'target': 'tests.D',
'source': 'tests.B'
},
# {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these commented lines unless they have some purpose I'm missing.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.31%) when pulling 8d8ccb5 on murphyke:issue-17 into 2982b10 on cbmi:master.

@murphyke
Copy link
Member Author

murphyke commented Nov 5, 2014

@naegelyd Thanks for the comments. Let me know when you are done with comments and I will update.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.31%) when pulling 70f12cb on murphyke:issue-17 into 2982b10 on cbmi:master.

# Model level..
elif source == self._excluded_joins.get(target):
return False
# Definition of required join: for the specified target,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment can be removed. It doesn't directly describe any code and I think required join is fairly obvious since the idea of a required route is well described in other comments above.

It is now an error to specify more than one required route with the
same target (ValueError is raised).

It is now possible to define multiple excluded routes involving the
same target model.  Previously, the last defined exclusion route for
a target model would silently replace any other such routes.

Signed-off-by: Kevin Murphy <murphyke@email.chop.edu>
@coveralls
Copy link

Coverage Status

Coverage increased (+0.28%) when pulling 9e31393 on murphyke:issue-17 into 2982b10 on cbmi:master.

# \ / \ |
# J H
# | |
# K I
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at this lovely ascii art.

bruth added a commit that referenced this pull request Nov 6, 2014
Fix bugs in required and excluded routes
@bruth bruth merged commit aaa6abd into chop-dbhi:master Nov 6, 2014
@bruth
Copy link
Contributor

bruth commented Nov 6, 2014

Thanks @murphyke for fixing this issue and @naegelyd for reviewing it.

@bruth
Copy link
Contributor

bruth commented Nov 11, 2014

I am running into an issue when using the symmetrical flag. It's been a long time since I originally wrote this code, however I now remember how join vs. join + field are differentiated. The changes in this PR have changed the behavior of the following routes:

'required_routes': [{
    'source': 'production.audiogramtest',
    'target': 'production.audiogramresult',
    'field': 'audiogramresult.test',
    'symmetrical': True,
}, {
    'source': 'production.encounter',
    'target': 'production.audiogramtest',
}, ...]

The first route is conditional on a join occurring between audiogramtest and audiogramresult. In this case the audiogramresult.test field must be used and since symmetrical is true, this applies to both directions. The second route is more of a declaration -- when joining to audiogramtest come from encounter. The routes could be considered conflicting since a join from audiogramresultaudiogramtest could never occur since the second route states joining to encounteraudiogramtest is required.

Of course this distinction of condition vs. declaration is not implemented. It is only the latter. I am not suggesting this is a bug in this PR, but it uncovered the distinction. However, the allow_redundant_targets block does not consider the symmetrical flag which means two sources could be declared for the same target (that is the bug).

@murphyke One unrelated question I would like to ask is why did you choose to replace the joins with join_fields and remove the joins (target → source) map? I only realized now that you changed the _join_allowed logic to loop through the _required_joins rather than using a dict lookup (as it was before).

@murphyke
Copy link
Member Author

@bruth I changed the data structures to allow defining multiple excluded routes involving the same target model. In the PR comment I alluded to the fact that the lookup was now less efficient. I guessed that this wouldn't matter since the modeltrees would in general be "small" and wouldn't be built very often. It would also be possible to continue keying on target but have the dict values be lists instead of single values.

As the keys became (source, target) tuples, it seemed to simplify things to store the optional field as the dict value. It was partly that simplification that caused me to make that choice.

@bruth
Copy link
Contributor

bruth commented Nov 11, 2014

@murphyke Understood and thanks. I pushed the fix for checking for redundant targets when symmetrical is true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants