Composer gives a dependency error with interdependent object definitions
You are running composer to add or modify a set of object definitions where one object is dependent on another in the same definition. An error is given for the dependency, even though the syntax of the definition is correct.
Cause and solution:
Composer validates objects in the order that they are presented in the command or the definition file. For example, you define two jobs, and the first-defined (job_tom) has a follows dependency on the second-defined (job_harry). The object validation tries to validate the follows dependency in job_tom but cannot find job_harry so gives an error and does not add the job to the database. However, it then reads the definition of job_harry, which is perfectly valid, and adds that to the database.
Similarly, this problem could arise if you define that a job needs a given resource or a Job Scheduler needs a given calendar, but you define the resource or calendar after defining the job or Job Scheduler that references them.
This problem applies to all composer commands that create or modify object definitions.
- The first job defined (job_tom) now finds the second job (job_harry) which was added to the database initially.
- You receive a "duplicate job" error for the second.
Alternatively, you can edit the object definition and retry the operation with just the object definition that gave the error initially.
To ensure that the problem does not reoccur, always remember to define objects in the order they are to be used. Define depending jobs and job streams before dependent ones. Define referred objects before referring objects.
In the example above, the problem would not have occurred when using add, new, create, or modify if the job definition of job_harry preceded that of job_tom. job_harry would have been added to the database, so the validation of job_tom would have been able to verify the existence of job_harry. Because the validate command does not add job_harry to the database, the validation of the follows dependency in job_tom fails.
There is no workaround for this problem when using validate. All you can do is to ensure that there are no interdependencies between objects in the object definition file.