Skip to content

Prohibit the use of / in component names#561

Open
daniel-thom wants to merge 6 commits intoIS4from
psy-issue-1647
Open

Prohibit the use of / in component names#561
daniel-thom wants to merge 6 commits intoIS4from
psy-issue-1647

Conversation

@daniel-thom
Copy link
Copy Markdown
Contributor

No description provided.

luke-kiernan and others added 5 commits February 16, 2026 21:03
Adds docstrings for exported types and functions that were missing them:
AbstractDeterministic, FunctionData, ProductionVariableCostCurve,
CompressionTypes, NormalizationTypes, UnitSystem, get_num_components,
and make_logging_config_file. Uses @doc macro for @scoped_enum types
since they expand to module definitions that can't use standard docstrings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change units_info field type from Union{Nothing, UnitsData} (abstract) to
Union{Nothing, SystemUnitsSettings} (concrete). This allows the compiler
to infer the type of units_info.base_value after an isnothing check,
eliminating dynamic dispatch in hot paths like get_value/set_value.

Benchmark impact (PSY ACTIVSg10k, 15k component get/set loop):
  Before: 4.0 ms (174k allocations)
  After:  552 μs (19k allocations) — 7.3x faster

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use concrete type for units_info field
Copy link
Copy Markdown

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

Adds validation to prohibit / in component names (to avoid HDF5 dataset path issues), with an escape hatch via an environment variable.

Changes:

  • Introduces _validate_component_name and enforces it when adding components and renaming components.
  • Adds tests asserting / is rejected by default and accepted when SIENNA_DISABLE_COMPONENT_NAME_CHECKS=true.

Reviewed changes

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

File Description
src/components.jl Adds component-name validation and applies it in _add_component! and set_name!.
test/test_system_data.jl Adds test coverage for invalid / in names and env-var bypass behavior.

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

Comment thread src/components.jl Outdated
Comment thread test/test_system_data.jl Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.94%. Comparing base (f0bf417) to head (83f3820).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #561      +/-   ##
==========================================
+ Coverage   77.81%   78.94%   +1.13%     
==========================================
  Files          75       75              
  Lines        6680     6597      -83     
==========================================
+ Hits         5198     5208      +10     
+ Misses       1482     1389      -93     
Flag Coverage Δ
unittests 78.94% <100.00%> (+1.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/components.jl 86.70% <100.00%> (+2.60%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


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

Comment thread test/test_system_data.jl
Comment on lines +90 to +94
withenv("SIENNA_DISABLE_COMPONENT_NAME_CHECKS" => "true") do
data2 = IS.SystemData()
slash_component = IS.TestComponent("E/W", 5)
IS.add_component!(data2, slash_component)
@test IS.get_name(slash_component) == "E/W"
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The test mutates the global ENV and then unconditionally deletes the key in finally, which will drop any pre-existing value and can leak state to subsequent tests in the same process. Prefer Base.withenv("SIENNA_DISABLE_COMPONENT_NAME_CHECKS" => "true") do ... end (or save/restore the previous value) so the original environment is reliably restored.

Copilot uses AI. Check for mistakes.
@jd-lara jd-lara changed the base branch from main to IS4 April 15, 2026 20:34
@jd-lara
Copy link
Copy Markdown
Member

jd-lara commented Apr 15, 2026

@daniel-thom to avoid breaking users during the current version I suggest we do this in IS4.

Comment thread src/components.jl
# Refer to https://github.com/NREL-Sienna/PowerSystems.jl/issues/1647 for the trigger of
# this rule. The '/' character could also cause problems if we ever wanted to use the
# component name as a file or directory name.
const INVALID_COMPONENT_NAME_CHARACTERS = ('/',)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@josephmckinsey we need to enforce this somewhere in the DB and Schema for the existing versions that's fine but in the future IS4 and PSY6 we should eliminate it

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.

5 participants