Issue:
The following attributes were entered when creating a new data source :
Host: {attribute('host','User')}
Port: {attribute('port','Tenant')}
Database: {attribute('dbname','Server')}
URL: jdbc:postgresql://{attribute('host','User')}:{attribute('port','Tenant')}/{attribute('dbname','Server')}
User Name: {attribute('userName')}
Password: {attribute('password')}
After clicking on the Test Connection button, the following error was generated:
Substitution error in resource /organizations/organization_1/datasources/AttrDSTest, field 'url'. Attribute 'host' is not defined in the User Profile.
These attribute parameters have already been defined under Manage -> Server Settings -> Server Attributes and they also appear under the User's profile as Inherited attributes.
What is the reason for the error and how can this be resolved ?
Solution:
There are two ways to reference attribute values, Categorical and Hierarchical. Categorical references does not take into account inherited attributes at the specified level.
By setting {attribute('host','User')} or {attribute('port','Tenant')} or {attribute('dbname','Server')} means it is referencing the attribute values at the respective categorical level. Therefore, by defining {attribute('host','User')}, the 'host' attribute value must be explicitly set at the User level. Doing this will override the 'host' attribute inheritance from true to false and resolve the error. Like-wise, the port attribute value must be explicitly set at the Organization level.
By default, the attribute parameters at the User and Tenant level are inherited from the Server attributes and can be referenced by using Hierarchical value reference:
{attribute('host')}
{attribute('port')}
The server searches for an attribute with the given name in the following order, stopping and returning the first value that it finds:
- At the user level
- At the organization level including parent organizations
- At the server level.
Note that the following will also resolve the error:
{attribute('host', 'Server')}
{attribute('port', 'Server')}
but this is a categorical reference to the server attributes.
Another thing to be mindful of is when a categorical reference is set as attribute('dbname','Tenant')} and the 'dbname' was explicitly set at the organization level, the Test Connection can fail with similar error if tested under a 'superuser' account:
Substitution error in resource /public/Data_Sources/AttrDSTest, field 'url'. Attribute 'dbname' is not defined in the Tenant Profile.
In order to test the attribute datasource, log out and log in to the organization level as a user, for example jasperadmin, before carrying out the Test Connection.
Recommended Comments