Skip to content

BUG: Manually adding a container without a module to the registry gives malformed name #341

@tangkong

Description

@tangkong

Expected Behavior

Adding items to the container registry, though not typically used, should be supported for interactive sessions / sandbox testing.

Current Behavior

Adding an item to the container registry runs through this code path

if the class added was defined interactively, it may have a module name of __main__, which results in an empty string being stored as a module name. This results in the class being stored with a key like entry_name..TestClass

In general it's not suggested to do this, since without an importable module the class is transient, but it may be worth supporting this for notebook sessions

Possible Solution(s)

  • Expand the documentation to dissuade people from doing this
  • Use a separate code path for manual assignment vs entrypoint collection
    • For manual additions, just use the provided name (to align setitem and getitem)

Steps to Reproduce (for bugs)

  1. ipython
  2. define a test class: class Test: ...
  3. happi.containers.HappiRegistry()['ItemName'] = Test
  4. Examine keys list(happi.containers.HappiRegistry().items()) = ('ItemName..Test', __main__.Test)

Context

Revealed in discussions with HZB about their use of happi

Your Environment

happi 2.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions