Skip to content

Conversation

Copy link

Copilot AI commented Nov 19, 2025

Fix site configuration name not being set from chimera.config

Problem

When configuring a site in chimera.config with a custom name (e.g., "Swope"), the site's name parameter was not being set, and it defaulted to "UFSC" instead. This affected the FITS header value for "SITE".

Example from issue:

site:
  name: Swope
  latitude: "-70:42:00.877"
  longitude: "-29:00:43.175"
  altitude: 2187

Expected: SITE = 'Swope'
Actual (before fix): SITE = 'UFSC'

Root Cause

In chimera_config.py, the _parse_config() method used config.pop("name") to extract the name for URL construction, which permanently removed it from the configuration dictionary. When the Site object was created, it never received the "name" parameter.

Initial Fix (commit 8f5452b) - Caused Regression

Added name back to config for ALL objects, but this broke objects like Scheduler that don't accept name as a configuration parameter:

ChimeraObjectException: Error configuring tcp://127.0.0.1:6379/Scheduler/fake. ('invalid option: name.')

Final Solution (commit 077925d)

Modified _parse_config() to accept a preserve_name parameter that is only set to True when parsing Site configuration:

def _parse_config(
    self, config: dict[str, Any], preserve_name: bool = False
) -> tuple[URL, dict[str, Any]]:
    host = config.pop("host", self.host)
    port = config.pop("port", self.port)
    cls = config.pop("type")
    name = config.pop("name")

    url = parse_url(f"tcp://{host}:{port}/{cls}/{name}")
    # Add name back to config for objects that use it as a configuration parameter (e.g., Site)
    if preserve_name:
        config["name"] = name
    return url, config

When parsing Site:

site_url, site_conf = self._parse_config(site_config, preserve_name=True)

Verification

Site configuration: Name preserved in config, appears in FITS headers
Scheduler configuration: Name NOT in config, no "invalid option" error
Telescope configuration: Name NOT in config, no "invalid option" error
Autofocus configuration: Name NOT in config, no "invalid option" error
Linting: Passed ruff checks
Security: Passed CodeQL scan (0 alerts)

Impact

  • Fixes original issue: Site name from chimera.config now appears in FITS headers
  • Fixes regression: Scheduler and other objects no longer break with "invalid option: name"
  • Minimal change: Only 7 insertions, 4 deletions in production code
  • Targeted fix: Only affects Site configuration parsing
  • Backward compatible: No breaking changes to other object types

Fixes #231

Original prompt

This section details on the original issue you should resolve

<issue_title>site configuration -> headers</issue_title>
<issue_description>For some reason, if I configure this site on chimera.config:

site:
  name: Swope
  latitude: "-70:42:00.877"
  longitude: "-29:00:43.175"
  altitude: 2187
  flat_alt: 80
  flat_az : 10

I still get this header key on my site:

SITE    = 'UFSC    '           / Site name (in config)                          

where it should be Swope instead of UFSC.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The _parse_config method was removing 'name' from the config dict, preventing
it from being set on Site objects. Now the name is added back to the config
after being used for URL construction, allowing it to properly configure the
Site's name parameter.

Co-authored-by: wschoenell <1873811+wschoenell@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix site header to display correct site name Fix site name not being applied from chimera.config Nov 19, 2025
Copilot AI requested a review from wschoenell November 19, 2025 00:22
Copy link
Contributor

@wschoenell wschoenell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot: proposed fixes work for the Site, but breaks for other classes where the name is an invalid configuration, like here:

                               File                                                                                  
                             "/Users/william/workspace/chimera/chimera-swope/.venv/lib/python3.13/site               
                             -packages/chimera/core/manager.py", line 278, in add_class                              
                                 raise ChimeraObjectException(f"Error configuring {url}. ({e})")                     
                             chimera.core.exceptions.ChimeraObjectException: Error configuring                       
                             tcp://127.0.0.1:6379/Scheduler/fake. ('invalid option: name.') 

Copy link
Contributor

@wschoenell wschoenell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot: proposed fixes work for the Site, but breaks for other classes where the name is an invalid configuration, like here:

                               File                                                                                  
                             "/Users/william/workspace/chimera/chimera-swope/.venv/lib/python3.13/site               
                             -packages/chimera/core/manager.py", line 278, in add_class                              
                                 raise ChimeraObjectException(f"Error configuring {url}. ({e})")                     
                             chimera.core.exceptions.ChimeraObjectException: Error configuring                       
                             tcp://127.0.0.1:6379/Scheduler/fake. ('invalid option: name.') 

The previous fix added 'name' back to all object configs, but this breaks
objects like Scheduler that don't accept 'name' as a configuration parameter.
Now using a preserve_name flag that is only set to True when parsing Site
configuration, preventing "invalid option: name" errors for other objects.

Co-authored-by: wschoenell <1873811+wschoenell@users.noreply.github.com>
Copy link
Author

Copilot AI commented Nov 19, 2025

@copilot: proposed fixes work for the Site, but breaks for other classes where the name is an invalid configuration, like here:

...

Fixed in 077925d. The issue was that my initial fix added name back to the config for all objects. Now _parse_config() accepts a preserve_name parameter that is only set to True when parsing Site configuration. This ensures:

  • Site objects receive the configured name
  • Other objects (Scheduler, etc.) don't get an invalid "name" parameter

The fix has been tested with both Site and Scheduler configurations.

Copilot AI requested a review from wschoenell November 19, 2025 06:19
@wschoenell wschoenell marked this pull request as ready for review November 19, 2025 18:36
@wschoenell wschoenell requested a review from phsilva November 19, 2025 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

site configuration -> headers

2 participants