Author Topic: Package.Alias not updated before Package.Update  (Read 6672 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +547/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Package.Alias not updated before Package.Update
« 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'

Code: [Select]
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

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Package.Alias not updated before Package.Update
« Reply #1 on: December 24, 2020, 08:12:24 pm »
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
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +547/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Alias not updated before Package.Update
« Reply #2 on: December 24, 2020, 08:28:02 pm »
If I try it like that I get an exception

Code: [Select]
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"

Code: [Select]
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

qwerty

  • EA Guru
  • *****
  • Posts: 13570
  • Karma: +395/-301
  • I'm no guru at all
    • View Profile
Re: Package.Alias not updated before Package.Update
« Reply #3 on: December 24, 2020, 11:56:22 pm »
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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +547/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Alias not updated before Package.Update
« Reply #4 on: December 25, 2020, 12:02:33 am »
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13136
  • Karma: +547/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Package.Alias not updated before Package.Update
« Reply #5 on: December 30, 2020, 05:42:08 pm »
After getting an email from support confirming it as an issue to be fixed, I now got a second email:

Quote
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:
Quote
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