CLIxIndia-Dev / CLIxIndia-Dev/MiTiRobot
Getting the "root" element?
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
So you'll have to educate me on this, but I'm unclear if this code does what you want it to (~lines 92-95):
```
top_level_elements = Element.objects.filter(level=0) # this is a string not an element object
for x in top_level_elements:
if str.lower(x.name) == "start":
element = x
```
Are you trying to get the first `start` Element, or the last one, assigned to the `element` variable? If you really start supporting multiple dialog roots, won't you have to change this code to account for multiple `start` Elements? (and how would you do that? At the very least, you might need a `break` statement here, or otherwise grab the first one back from the queryset).
This also seems like an opportunity to break this code out into its own method and gave it a clarifying name. And of course, add a set of tests (when there are no elements named `start`, 1 element, multiple, etc.), depending on what is the current use case you're supposed to be supporting.
Right now I think the `on_chat_message` method breaks if there are no elements named `start` (line 295, `user.last_node=element` might throw an exception), but maybe that's not a possible state to be in?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting the code around lines 92-95 and the on_chat_message method near line 295, focusing on how Element.objects.filter(level=0) selects the root and how element is used when no start element exists. Clarify whether one or multiple start Elements are supported, then add tests for no start element, one start element, and multiple start elements; done means the selected-root behavior and empty case are explicit and covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100