1

I have enum class, that is generated based on distinct names in Postgres table, like this.

CustomProperty = StrEnum('CustomProperty',
                     [(i['metric_name'], i['metric_name'])
                      for i in PostgresConnection().distinct_metrics()])

That is, when the application is loaded, the CustomProperty class gets initiated and stores the list of available properties.

Sometimes there appears to happen that new metrics are added to the table, but they are not getting dynamically added to this CustomProperty. So I need to reload the application, to reinitiate the class. I want to re-/initiate the class generation on call of certain function. How can it be done?

Graygood
  • 363
  • 1
  • 3
  • 18
  • 1
    Enums are not mutable and are singletons, and are not meant to be dynamically created. Why do you need an enum and not e.g. a dict? It also seems you're doing just string->the same string mapping (which is obsolete because enums can print their names as strings already). – h4z3 Feb 17 '20 at 12:24
  • `Enum`s can be [extended](https://stackoverflow.com/a/33680929/208880), although that's usually not a good idea. If you think it makes sense in your case, you can include that code in your app wherever you reload from postgres. – Ethan Furman Feb 17 '20 at 20:58

0 Answers0