Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _validate_config(app: App):
try:
validate_config(app, app.config)
except ValidationError as e:
msg = f"Validation Error: {e}"
logger.exception(msg)
click.get_current_context().exit(1)
def _validate_unique_state_names(state_machine):
state_name_counts = collections.Counter([
x.name for x in state_machine.states
])
invalid_states = [x for x, y in state_name_counts.items() if y > 1]
if invalid_states:
raise ValidationError(
f"States {invalid_states!r} are not unique in "
f"{state_machine.name}",
def _validate_all_states_exist(state_machine):
state_names = set(x.name for x in state_machine.states)
for state in state_machine.states:
for destination_name in state.next_states.all_destinations():
if destination_name not in state_names:
raise ValidationError(f"{destination_name} does not exist")
label_state_machine=state_machine.name,
).subquery()
invalid_labels_and_states = app.session.query(
states_by_rank.c.label_name,
states_by_rank.c.new_state,
).filter(
states_by_rank.c.rank == 1,
~(
states_by_rank.c.new_state.in_(states) |
states_by_rank.c.new_state.is_(None)
),
).all()
if invalid_labels_and_states:
raise ValidationError(
f"{len(invalid_labels_and_states)} nodes in states that no "
f"longer exist",
def _validate_route_start_to_end(state_machine):
graph = _build_graph(state_machine)
if not networkx.is_connected(graph):
raise ValidationError("Graph is not fully connected")