Sparx Systems Forum
Enterprise Architect => Bugs and Issues => Topic started by: Geert Bellekens on December 24, 2020, 08:07:41 pm
-
If you set the Package.Alias before the package has been saved using Update(), the alias doesn't stick.
You have to first Update() the package and only after that setting the Alias has any effect.
Steps to Reproduce:
- Execute the script below
- Notice that the first line of the output reads "Alias before update: ''" where it should read Alias before update: 'Alias before update'
sub main
dim package as EA.Package
set package = Repository.GetTreeSelectedPackage
dim newPackage as EA.Package
set newPackage = package.Packages.AddNew("NewPackage","")
newPackage.Alias = "Set Before update"
Session.Output "Alias before update: '" & newPackage.Alias & "'"
newPackage.Update
newPackage.Alias = "Set after update"
Session.Output "Alias after first update: '" & newPackage.Alias & "'"
newPackage.Update
Session.Output "Alias after second update: '" & newPackage.Alias & "'"
end sub
main
Reported
Geert
-
Years ago I adopted the convention of never using a Package object's pass-through properties which are really in Element, but always using the explicit Package.Element.Alias etc.
I don't remember precisely what prompted this, but it was something like what you describe.
/Uffe
-
If I try it like that I get an exception
dim package as EA.Package
set package = Repository.GetTreeSelectedPackage
dim newPackage as EA.Package
set newPackage = package.Packages.AddNew("NewPackage","")
newPackage.Element.Alias = "Set Before update"
Object required: 'newPackage.Element'
Adding an Update() before setting the newPackage.Element.Alias makes the exception go away.
The API should either raise an exception when setting the package.Alias before updating (as does setting package.Element.Alias) or it should create the package.Element as soon as the Package is created.
Failing silently is not acceptable.
Geert
-
Same with assigning anything (like stereotype) to the element-twin of a package. Ever been so: you need to Update a package once before you can modify its element-twin. EAUI.
q.
-
Same with assigning anything (like stereotype) to the element-twin of a package. Ever been so: you need to Update a package once before you can modify its element-twin. EAUI.
q.
I know, but that doesn't mean it isn't a bug. I can't think of an explanation that makes this silent fail OK.
I must have stumbled on something similar a number of times, but today I decided to send in a bug report.
Geert
-
After getting an email from support confirming it as an issue to be fixed, I now got a second email:
On further investigation, this turned out not to be a bug.
When the new package is created, it needs to first be saved by calling update interface, otherwise setting alias will fail to get the actual element and hence not be saved.
So it's a feature, not a bug :-\
I replied:
I'm sorry but that is nonsense. If the package needs to be saved first, it should raise an exception.
Failing silently like that is not acceptable.
Why is the behavior different from calling newPackage.Element.Alias = "Set Before update" right after the creation?
If I try that I get an exception, while that is really doing exactly the same thing.
The property Package.Alias is merely a shortcut for Package.Element.Alias
Sometimes I wonder why I even bother... :(
Geert