Fixes #2721 Path of a parameter of a Passive Transport cannot be resolved when "Create process rate" is enabled#2722
Conversation
…lved when "Create process rate" is enabled
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where path resolution failed for parameters in Passive Transport when "Create process rate" is enabled. The issue occurred because the process rate parameter creation did not correctly adjust path references when the path started with the container (process) name itself.
Key changes:
- Enhanced path adjustment logic to handle paths that start with the process/container name
- Added unit test coverage for the specific case where a path starts with the process name
- Refactored the path adjustment method for better clarity and maintainability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs |
Enhanced adjustRelativePath method to handle paths starting with the process name by prepending two parent container references, allowing proper resolution when paths reference parameters within the process container itself |
tests/OSPSuite.Core.Tests/Domain/ProcessRateParameterCreatorSpecs.cs |
Added test case for path starting with process name ("Reaction", "C") to verify it correctly adjusts to include two parent container references |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/OSPSuite.Core/Domain/Mappers/ProcessRateParameterCreator.cs
Outdated
Show resolved
Hide resolved
| _kinetic.AddObjectPath(_formulaUsablePathFU); | ||
| _formulaUsablePathBW = new FormulaUsablePath("Organism", "BW").WithAlias("BW"); | ||
| _kinetic.AddObjectPath(_formulaUsablePathBW); | ||
| _formulaUsablePathC = new FormulaUsablePath("Reaction", "C").WithAlias("C"); |
There was a problem hiding this comment.
I don;t understand. What's this absolute path "Reaction"?
There was a problem hiding this comment.
oh that' sthe name of the reaction defined below. This is super confusiong. Can we set the name higer up
I don't understand why the path look like this
why would the path in the process rate parmaeter be "P1|C". Should not that be "..|C"? or sthg like this
It feels like it;s absolute relative to the parent container. Do we have sthg like this anyewhere else?
There was a problem hiding this comment.
Yeah we could make the new path ..|C. It would also work rather than keeping the name of the process. I think I like that better too.
There was a problem hiding this comment.
Do we have sthg like this anyewhere else?
IDK how often it's used. In ObjectPath.Resolve we have this
//We have an absolute Path from the ref entity
if (string.Equals(firstEntry, refEntity.Name))
usePath.RemoveAt(0);
This removes the name if it matches the reference name. This has been working for some time already. But this is why it works when building the simulation, but not when adding the ProcessRate
msevestre
left a comment
There was a problem hiding this comment.
a bit confused with the use cas.e Implementation is fine
| _kinetic.AddObjectPath(_formulaUsablePathFU); | ||
| _formulaUsablePathBW = new FormulaUsablePath("Organism", "BW").WithAlias("BW"); | ||
| _kinetic.AddObjectPath(_formulaUsablePathBW); | ||
| _formulaUsablePathC = new FormulaUsablePath("Reaction", "C").WithAlias("C"); |
There was a problem hiding this comment.
oh that' sthe name of the reaction defined below. This is super confusiong. Can we set the name higer up
I don't understand why the path look like this
why would the path in the process rate parmaeter be "P1|C". Should not that be "..|C"? or sthg like this
It feels like it;s absolute relative to the parent container. Do we have sthg like this anyewhere else?
| // to compensate. That's because a container name can be ignored when a path is resolved from within that container | ||
| if (objectPath.Count == 2 && string.Equals(objectPath[0], processName)) | ||
| { | ||
| objectPath.AddAtFront(new ObjectPath(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER)); |
There was a problem hiding this comment.
@Yuri05 what do you think? should we make this case ..|..|ProcessName|ParameterName or remove the process name and go with ..|ParameterName
There was a problem hiding this comment.
..|ParameterName would be better for sure (and process name invariant)
There was a problem hiding this comment.
Well, yes, but in this case the process name is fixed because this is the ProcessRate parameter for the process.
But if we use the ..|ParameterName then it is the same as the case where the original path was only ParameterName
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| objectPath.AddAtFront(ObjectPath.PARENT_CONTAINER); | ||
| } | ||
| } | ||
| private void addAdditionalParentReference(IFormula formula, string processName) => formula.ObjectPaths.Each(x => adjustRelativePath(x, processName)); |
There was a problem hiding this comment.
The method uses an expression body with a lambda instead of a traditional method body. While this is syntactically valid, using an expression body for a method that only calls another method with side effects (Each with adjustRelativePath) reduces readability. Consider using a traditional method body with a foreach loop for better clarity, especially since the operation modifies the paths rather than returning a value.
| private void addAdditionalParentReference(IFormula formula, string processName) => formula.ObjectPaths.Each(x => adjustRelativePath(x, processName)); | |
| private void addAdditionalParentReference(IFormula formula, string processName) | |
| { | |
| foreach (var objectPath in formula.ObjectPaths) | |
| { | |
| adjustRelativePath(objectPath, processName); | |
| } | |
| } |
| return true; | ||
| // if the path starts with the process name then we need to replace the name with ".." | ||
| // to compensate. That's because a container name can be ignored when a path is resolved from within that container | ||
| if (objectPath.Count == 2 && string.Equals(objectPath[0], processName)) |
There was a problem hiding this comment.
The condition only handles paths with exactly 2 elements that start with the process name. If a path has 3 or more elements and starts with the process name (e.g., ["Reaction", "X", "Y"]), it won't be adjusted correctly. The condition should check if the path starts with the process name regardless of the total count. Consider changing the condition to just check if the first element matches the process name without the count restriction.
| if (objectPath.Count == 2 && string.Equals(objectPath[0], processName)) | |
| if (string.Equals(objectPath[0], processName)) |
|
|
||
| if (objectPath[0] == ObjectPath.PARENT_CONTAINER) | ||
| return true; | ||
| // if the path starts with the process name then we need to replace the name with ".." |
There was a problem hiding this comment.
There is an extra space in the comment: "the process" should be "the process".
| // if the path starts with the process name then we need to replace the name with ".." | |
| // if the path starts with the process name then we need to replace the name with ".." |
| private FormulaUsablePath _formulaUsablePathBW; | ||
| private SimulationBuilder _simulationBuilder; | ||
| private FormulaUsablePath _formulaUsablePathC; | ||
| private readonly string _processBuilderName = "Reaction"; |
There was a problem hiding this comment.
The field is declared as readonly but initialized inline instead of in the constructor. While this is valid C# syntax, it's inconsistent with the typical pattern in test classes where such fields are initialized in the Context method. Consider initializing this in the Context method for consistency, or use a const if the value never changes.
| private readonly string _processBuilderName = "Reaction"; | |
| private const string _processBuilderName = "Reaction"; |
Fixes #2721
Description
The path resolver can resolve paths that start with the container name, but the process rate parameter creation will not create the correct path adjustment for the process rate parameter.
Type of change
Please mark relevant options with an
xin the brackets.How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Reviewer checklist
Mark everything that needs to be checked before merging the PR.
This change requires a documentation updateabove is selectedScreenshots (if appropriate):
Questions (if appropriate):