Skip to content

Fix internal API service handling#21631

Merged
Rylan12 merged 1 commit intomainfrom
fix-services-internal-api
Feb 26, 2026
Merged

Fix internal API service handling#21631
Rylan12 merged 1 commit intomainfrom
fix-services-internal-api

Conversation

@Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Feb 26, 2026

Service blocks were accidentally left out of the internal API due to a type mismatch. Formula#to_hash_with_variations returns different types based on whether running via HOMEBREW_NO_INSTALL_FROM_API or not. If using the API, it returns JSON-ified values (i.e. everything is a string), but if not using the API, it returns a mix of symbols, pathnames, etc. This ultimately resulted in a mismatch where Homebrew::Service::from_hash attempted to search for the key "run" and turned up blank, because what it was looking for was listed under :run.

To solve this, let's stringify the keys before processing the variations hash into a FormulaStruct, that way keys throughout the hash are consistently strings. Note that values can still be non-strings, so I had to make another small change to process Pathnames correctly.

Unfortunately, this will require re-installing any affected formulae (once the API is regenerated) to actually install the service files.

Copilot AI review requested due to automatic review settings February 26, 2026 15:04
@Rylan12 Rylan12 enabled auto-merge February 26, 2026 15:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where service blocks were missing from the internal API due to a type mismatch between keys. The issue occurred because Formula#to_hash_with_variations returns different key types (symbols vs strings) depending on whether the API is being used or not, causing Service.from_hash to fail when looking for string keys in a hash with symbol keys.

Changes:

  • Add .deep_stringify_keys call in generate_formula_struct_hash to ensure consistent string keys throughout the hash
  • Update Service.replace_placeholders to accept Pathname objects in addition to strings and convert them to strings before processing

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Library/Homebrew/service.rb Updated type signature and implementation of replace_placeholders to handle Pathname values by converting them to strings
Library/Homebrew/api/formula/formula_struct_generator.rb Added deep_stringify_keys call after merge_variations to ensure all hash keys are consistently strings before processing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks!

@MikeMcQuaid
Copy link
Member

@Rylan12 CI failure looks relatively legit here?

@Rylan12
Copy link
Member Author

Rylan12 commented Feb 26, 2026

Oof yeah, I think so. Will look into fixing that later tonight

@Rylan12 Rylan12 force-pushed the fix-services-internal-api branch from 64d4f82 to 404e8e1 Compare February 26, 2026 19:02
@Rylan12 Rylan12 added this pull request to the merge queue Feb 26, 2026
Merged via the queue into main with commit 3a9833e Feb 26, 2026
36 checks passed
@Rylan12 Rylan12 deleted the fix-services-internal-api branch February 26, 2026 19:54
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.

3 participants