11338 invalid report alias#11354
Conversation
…n when there is an invalid character.
|
Only valid characters in report aliases are A–Z, a–z, 0–9, _, ., @ however \ApsimX\Tests\Simulation\DairyFarmManager has "/" in its alias (AboveGroundBiomass_kgDM/ha) therefore it fails acceptance tests. |
…expection when there is an invalid character." This reverts commit 4e0b318.
…asa/ApsimX into 11338-InvalidReportAlias
…les to correct format. Formatted Pasture (Prototypes) report variables to correct format.
There was a problem hiding this comment.
Pull request overview
This PR bumps the .apsimx file format to v217 and updates bundled resources/examples and the converter to better handle (or rewrite) report variable aliases which contain characters that are expected to be invalid under stricter parsing.
Changes:
- Bump file format version from 216 → 217 across many resource/example simulation files.
- Update
Converter.LatestVersionand add aUpgradeToVersion217converter step targeting report variable aliases. - Fix a couple of bundled
.apsimxexample/report variable strings so they conform to the expected report variable syntax.
Reviewed changes
Copilot reviewed 104 out of 104 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Prototypes/Pasture/Pasture.apsimx | Bump version and adjust a report variable expression so the as <alias> portion is syntactically valid. |
| Models/Resources/WinterCereal.json | Bump resource file format version to 217. |
| Models/Resources/WhiteClover.json | Bump resource file format version to 217. |
| Models/Resources/Wheat.json | Bump resource file format version to 217. |
| Models/Resources/WaterBalance.json | Bump resource file format version to 217. |
| Models/Resources/SurfaceOrganicMatter.json | Bump resource file format version to 217. |
| Models/Resources/Sugarcane.json | Bump resource file format version to 217. |
| Models/Resources/STRUM.json | Bump resource file format version to 217. |
| Models/Resources/SPRUM.json | Bump resource file format version to 217. |
| Models/Resources/Soybean.json | Bump resource file format version to 217. |
| Models/Resources/Sorghum.json | Bump resource file format version to 217. |
| Models/Resources/Slurp.json | Bump resource file format version to 217. |
| Models/Resources/SCRUM.json | Bump resource file format version to 217. |
| Models/Resources/RedClover.json | Bump resource file format version to 217. |
| Models/Resources/Potato.json | Bump resource file format version to 217. |
| Models/Resources/PlantainForage.json | Bump resource file format version to 217. |
| Models/Resources/Pinus.json | Bump resource file format version to 217. |
| Models/Resources/Peanut.json | Bump resource file format version to 217. |
| Models/Resources/OilPalm.json | Bump resource file format version to 217. |
| Models/Resources/Oats.json | Bump resource file format version to 217. |
| Models/Resources/Nutrient.json | Bump resource file format version to 217. |
| Models/Resources/Mungbean.json | Bump resource file format version to 217. |
| Models/Resources/MicroClimate.json | Bump resource file format version to 217. |
| Models/Resources/Maize.json | Bump resource file format version to 217. |
| Models/Resources/Lucerne.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Targhee.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Small Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Romney.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Polwarth.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Medium Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Large Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Delaine-Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Wool breeds/Corriedale.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Ujimqin Sheep.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Texel.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Suffolk.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Suffolk (US).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Southdown.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Southdown (US).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Ryeland.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Rambouillet.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Polypay.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Hampshire.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Finnsheep.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Dorset.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Columbia.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Cheviot.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Border Leicester.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Meat breeds/Blackface x Whiteface.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Crossbreds/Mongolian x Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Crossbreds/Dorset x Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Sheep/Crossbreds/Border Leicester x Merino.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Goats/Ujimqin Goats.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Jersey.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Holstein.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Guernsey.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Friesian.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Dairy Shorthorn.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Brown Swiss.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Dairy/Ayrshire.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Ujimqin x Charolais (2nd cross).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Ujimqin x Charolais (1st cross).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Ujimqin x Angus (2nd cross).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Ujimqin x Angus (1st cross).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Ujimqin Cattle.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/South Devon.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Simmental.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Limousin.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Hereford.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Chianina.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Charolais.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Charolais x Holstein.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Charolais x Friesian.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/British x Holstein.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/British x Friesian.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/British x Charolais.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/British x Brahman.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Brahman.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Beef Shorthorn.json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Angus(SRW625).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Angus(SRW542).json | Bump resource file format version to 217. |
| Models/Resources/GrazPlan/Genotypes/Cattle/Beef/Angus.json | Bump resource file format version to 217. |
| Models/Resources/Grapevine.json | Bump resource file format version to 217. |
| Models/Resources/Gliricidia.json | Bump resource file format version to 217. |
| Models/Resources/FodderBeet.json | Bump resource file format version to 217. |
| Models/Resources/Fertiliser.json | Bump resource file format version to 217. |
| Models/Resources/Eucalyptus.json | Bump resource file format version to 217. |
| Models/Resources/Chicory.json | Bump resource file format version to 217. |
| Models/Resources/Chickpea.json | Bump resource file format version to 217. |
| Models/Resources/Canola.json | Bump resource file format version to 217. |
| Models/Resources/Barley.json | Bump resource file format version to 217. |
| Models/Resources/AGPWhiteClover.json | Bump resource file format version to 217. |
| Models/Resources/AGPTallFescue.json | Bump resource file format version to 217. |
| Models/Resources/AGPRyegrass.json | Bump resource file format version to 217. |
| Models/Resources/AGPRhodes.json | Bump resource file format version to 217. |
| Models/Resources/AGPRedClover.json | Bump resource file format version to 217. |
| Models/Resources/AGPPhalaris.json | Bump resource file format version to 217. |
| Models/Resources/AGPPaspalum.json | Bump resource file format version to 217. |
| Models/Resources/AGPLucerne.json | Bump resource file format version to 217. |
| Models/Resources/AGPKikuyu.json | Bump resource file format version to 217. |
| Models/Resources/AGPCocksfoot.json | Bump resource file format version to 217. |
| Models/Resources/AGPBrowntop.json | Bump resource file format version to 217. |
| Examples/SWIM.apsimx | Fix broken report VariableNames entry and bump file format version compatibility. |
| APSIM.Core/ApsimFile/Converter.cs | Bump LatestVersion and add v217 upgrade hook to rewrite invalid report alias characters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// <summary> | ||
| /// Removes invalid character "/ " in alias | ||
| /// </summary> | ||
| /// <param name="root"></param> | ||
| /// <param name="fileName"></param> | ||
| private static void UpgradeToVersion217(JObject root, string fileName) | ||
| { | ||
| foreach (var report in JsonUtilities.ChildrenOfType(root, "Report")) | ||
| { |
There was a problem hiding this comment.
The issue is addressed in this PR. The intention is to write a converter to make sure existing apsimx files do not have invalid character. I will address the actual issue in my next PR.
| /// <summary> | ||
| /// Removes invalid character "/ " in alias | ||
| /// </summary> |
There was a problem hiding this comment.
Converter is intended to remove "/" in aliases alone. ReportVariables can have mathematical operator divide represented as / in the report variable. ex [Wheat].AboveGround.Wt/10
| string reportVariable = variableNames[i]; | ||
| // Only rewrite if BOTH patterns exist | ||
| if (reportVariable.Contains(" as ") && reportVariable .Contains("/")) | ||
| { | ||
| // Remove ONLY the slash inside the variable expression | ||
| int asIndex = reportVariable .IndexOf(" as ", StringComparison.Ordinal); // finds the exact position of " as " | ||
| string expr = reportVariable .Substring(0, asIndex); // experssion before " as " | ||
| string alias = reportVariable .Substring(asIndex); // experssion with " as " | ||
| string cleanedExpr = alias.Replace("/", ""); // Removes / in alias alone | ||
| string rewritten = expr + cleanedExpr ; | ||
| if (rewritten != reportVariable ) | ||
| { | ||
| variableNames[i] = rewritten; | ||
| changed = true; | ||
| } | ||
| } |
Resolves #11338
The entire alias group is optional because of the trailing ? in the pattern therefore the group is silently ignored. The validator ignored %@# etc., therefore it never threw exception. This PR resolve the issue and throws an exception when a invalid character is given in the alias.