ietf-tools / xml2rfc

Generate RFCs and IETF drafts from document source in XML according to the IETF xml2rfc v2 and v3 vocabularies
https://ietf-tools.github.io/xml2rfc/
BSD 3-Clause "New" or "Revised" License
65 stars 38 forks source link

fix: Reset seen_slugs cache on every prep run #1011

Closed jennifer-richards closed 1 year ago

jennifer-richards commented 1 year ago

The writers.preptool.slugify_name() helper kept a set of seen_slugs as a module-level variable. As a result, uniqueness among slugs was enforced for the entire lifetime of a module import, including across PrepToolWriter instances and across multiple calls to prep().

In xml2rfc itself, this appears to have been adding unnecessary "-2" suffixes on many HTML ids, at least in the tests. For datatracker's use of xml2rfc as a library, this was causing difficulties with long-lived celery workers by adding suffixes to prevent collisions between entirely separate drafts and eventually running out of unique slugs.

This makes the slugify_name() procedure a method on PrepToolWriter and resets the seen_slugs cache, now a property of the instance, on each invocation of prep()