﻿ticket,summary,type,release,owner,status,created,modified,_description,_reporter
14241,TicketStencilPlugin doesn't work if ticket types contain uppercase letters,defect,,tkob-trac,new,2023-07-28T18:39:21+02:00,2023-07-28T18:39:21+02:00,"I installed the TicketStencilPlugin on Trac 1.5.4 and Python 3.11, ran trac-admin deploy to install the .js file, and created a TicketStencilBug wiki page, but it didn't populate the ticket description for me. Looking at the source of the newticket page, I saw:

{{{
var _tracticketstencil={""_ticketstencil_default_type"":"""",""bug"":"""",""enhancement"":"""",""task"":""""};
}}}

So it was finding my ticket types, but not getting the stencil for any of them. Looking into it further, I found that the problem is that it sets the stencils, then in another loop, ends up clearing all of them. The `all_types` list has the ticket types in the original case, but the `ticket_type` variable is all lowercase. If a ticket type has uppercase letters, `all_types.remove(ticket_type)` will throw a ValueError('list.remove(x): x not in list') because of the case mismatch. Then when it later does ""Set defaults for remaining ticket types"", `all_types` will still contain all of the ticket types, and the stencils for all types will be set to the empty string.

Patch:

{{{
#!diff
Index: ticketstencil.py
===================================================================
--- ticketstencil.py    (revision 18549)
+++ ticketstencil.py    (working copy)
@@ -43,8 +43,8 @@
         all_types = [enum.name for enum in Type.select(self.env)]
         for name in self.wiki_system.get_pages('TicketStencil'):
             page = WikiPage(env = self.env, name = name)
-            ticket_type = name[prefix_len:].lower()
-            stencils[ticket_type] = page.text
+            ticket_type = name[prefix_len:]
+            stencils[ticket_type.lower()] = page.text
             try:
                 all_types.remove(ticket_type)
             except ValueError:
}}}",khym@…
