Repository: TabbycatDebate/tabbycat

Issue:
Crash when generating QF draw (WS)
**Running:**  a1ca1a390866199e1884db12c215ddaa867a98dc

When generating the draw for the first elimination round in a WS tournament, I encountered this exception:

```python
[2023-07-09 12:01:47,564] ERROR django.request: Internal Server Error: /xxx-yyz/admin/draw/round/7/create/
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/mixins.py", line 135, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/tcd/tabbycat/tournaments/mixins.py", line 125, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/tcd/tabbycat/draw/views.py", line 664, in post
    manager.create()
  File "/tcd/tabbycat/draw/manager.py", line 157, in create
    drawer = DrawGenerator(self.teams_in_debate, generator_type, teams,
  File "/tcd/tabbycat/draw/generator/__init__.py", line 93, in DrawGenerator
    return klass(teams, results, rrseq, **kwargs)
  File "/tcd/tabbycat/draw/generator/common.py", line 182, in __init__
    super().__init__(teams, results, rrseq, **kwargs)
  File "/tcd/tabbycat/draw/generator/common.py", line 73, in __init__
    raise ValueError("Unrecognised options: " + ", ".join(unrecognised))
ValueError: Unrecognised options: avoid_conflicts
```

I quickly patched around it like so and we manually confirmed the draw was correct:

```diff
diff --git a/tabbycat/draw/generator/common.py b/tabbycat/draw/generator/common.py
index 2a61de6ea..3d7167aa1 100644
--- a/tabbycat/draw/generator/common.py
+++ b/tabbycat/draw/generator/common.py
@@ -68,9 +68,10 @@ class BaseDrawGenerator:
         # Compute the full dictionary of default options
         self.options = self.BASE_DEFAULT_OPTIONS.copy()
         self.options.update(self.DEFAULT_OPTIONS)
+        print(self.__class__)
         unrecognised = [key for key in kwargs if key not in self.options]
-        if unrecognised:
-            raise ValueError("Unrecognised options: " + ", ".join(unrecognised))
+#        if unrecognised:
+#            raise ValueError("Unrecognised options: " + ", ".join(unrecognised))
         self.options.update(kwargs)
 
     def generate(self):
```

Of course, this is not a fix for the problem, just avoiding the symptoms. **I intend to find the cause of this issue and fix it in the following days**, bu I'm dropping an issue here so I don't forget


Discussion:
The quick solution should be to add `avoid_conflicts` to `BASE_DEFAULT_OPTIONS` in `draw/generator/common.py:161`.
Encountered the same issue, made a similar quick fix it by removing `"avoid_conflicts"` from `get_relevant_options` in `BaseDrawManager`:
```diff
diff --git a/tabbycat/draw/manager.py b/tabbycat/draw/manager.py
index b59216797..8e976972c 100644
--- a/tabbycat/draw/manager.py
+++ b/tabbycat/draw/manager.py
@@ -62,7 +62,7 @@ class BaseDrawManager:
 
     def get_relevant_options(self):
         if self.teams_in_debate == 'two':
-            return ["avoid_institution", "avoid_history", "history_penalty", "institution_penalty", "pullup_debates_penalty", "side_penalty", "pairing_penalty", "avoid_conflicts"]
+            return ["avoid_institution", "avoid_history", "history_penalty", "institution_penalty", "pullup_debates_penalty", "side_penalty", "pairing_penalty"]
         else:
             return []
```

I have no idea if this breaks another draw type or something else - I'm basically reverting part of 32b30338daf248f20c88b4ba8c26c57df083c68e. I guess that's karma for using a dev version.

Resolving patch:
diff --git a/tabbycat/draw/generator/common.py b/tabbycat/draw/generator/common.py
--- a/tabbycat/draw/generator/common.py
+++ b/tabbycat/draw/generator/common.py
@@ -167,6 +167,7 @@ class BasePairDrawGenerator(BaseDrawGenerator):
         "side_penalty"          : 0,
         "pullup_debates_penalty": 0,
         "pairing_penalty"       : 0,
+        "avoid_conflicts"       : "off",
     }
 
     TEAMS_PER_DEBATE = 2


Test patch: