From f0c51680679b9eb082c4455af28fef8de0165470 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sat, 26 Jul 2025 22:56:08 +0200 Subject: [PATCH] trap bug that Tom B found --- parsers/survex.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/parsers/survex.py b/parsers/survex.py index 69fd8cf..ffced3d 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -2652,10 +2652,20 @@ def parse_one_file(fpath): # --------------------------------------in progress-- """ cave = find_cave_from_path(svxpath) if cave: - cave_svxpath = cave.survex_file[:-4] # remove .svx - fileroot = SurvexFile.objects.get(path=cave_svxpath) - print(f" - Setting the root survexfile for this import: {svxpath} to be that for cave {cave}") + if cave.survex_file: # i.e. cave has been fully created and has a value for this + cave_svxpath = cave.survex_file[:-4] # remove .svx + else: + cave.survex_file = svxpath + ".svx" + save(cave) + cave_svxpath = svxpath + try: + fileroot = SurvexFile.objects.get(path=cave_svxpath) + except: + fileroot = SurvexFile.objects.create(path=cave_svxpath, cave=cave) + print(f" !! - No SurvexFile object found for {svxpath=}, making a new one..") + print(f" - Setting the root survexfile for this import: {svxpath} to be that for cave {cave} {cave.survex_file=}") return fileroot + # make a dummy SurvexFile object, which will be removed later dummyroot = SurvexFile(path=svxpath)