Skip to content

Commit

Permalink
fast_deepcopy_system: fix shared units references bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Dec 26, 2024
1 parent d318429 commit 5a5096e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2696,5 +2696,9 @@ function fast_deepcopy_system(
time_series_directory = deepcopy(sys.time_series_directory),
name = deepcopy(sys.metadata.name),
description = deepcopy(sys.metadata.description))
# deepcopying sys.data separately from sys.units_settings broke the shared units references, so we have to fix them here
for comp in iterate_components(new_sys)
comp.internal.units_info = new_sys.units_settings
end
return new_sys
end
4 changes: 4 additions & 0 deletions test/test_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ end
[:time_series_manager, :supplemental_attribute_manager][[skip_ts, skip_sa]],
),
)

# We copy the SystemData separately from the other System fields, so the egal-ity of these references could get broken
generator = get_component(ThermalStandard, sys2, "322_CT_6")
@test sys2.units_settings === generator.internal.units_info
end
end

Expand Down

0 comments on commit 5a5096e

Please sign in to comment.