PY: foreign keys queries, refactored into single file + detail::.