8000 PrimaveraScheduler leaves Duration null on ALAP activities; scheduling the same ProjectFile again throws "Task has no duration value" · Issue #977 · joniles/mpxj · GitHub
[go: up one dir, main page]

Skip to content

PrimaveraScheduler leaves Duration null on ALAP activities; scheduling the same ProjectFile again throws "Task has no duration value" #977

Open

Description

@james-wagner11

After PrimaveraScheduler.schedule() runs, every activity with an As Late As Possible constraint has a null Duration. Calling schedule() again on the same ProjectFile then fails:

org.mpxj.cpm.CpmException: Task has no duration value: [Task id=2 uniqueID=2 activityID=A1010 name=A1010]

The same applies to a PMXML file written from a scheduled project. It carries the empty durations, so reading it back and scheduling it fails too. An XER written the same way does not.

Repro

MPXJ 16.10.0 (PyPI wheel, JPype 1.7.1, OpenJDK 17). A three-activity project built in code:

  • A1000, 5 days
  • A1010, 3 days, constraint AS_LATE_AS_POSSIBLE
  • A1020, 10 days
  • A1000 tied finish-to-start to both A1010 and A1020
PrimaveraScheduler scheduler = new PrimaveraScheduler();
scheduler.schedule(project, start);
// A1010.getDuration() is now null; A1000.getDuration() is still 40.0h
scheduler.schedule(project, start);   // throws CpmException: Task has no duration value
Full Python (JPype) script; the calls are the same in Java
import jpype, mpxj  # noqa: F401
jpype.startJVM()
from java.time import LocalDateTime
from org.mpxj import (ProjectFile, Duration, TimeUnit, ActivityType, ConstraintType, Relation, RelationType,
                      PercentCompleteType)
from org.mpxj.cpm import PrimaveraScheduler

p = ProjectFile()
cal = p.addDefaultBaseCalendar()
p.getProjectProperties().setDefaultCalendar(cal)
start = LocalDateTime.of(2026, 1, 5, 8, 0)
p.getProjectProperties().setStartDate(start)
p.getProjectProperties().setPlannedStart(start)

def task(name, days, alap=False):
    t = p.addTask(); t.setName(name); t.setActivityID(name)
    d = Duration.getInstance(days * 8, TimeUnit.HOURS)
    t.setDuration(d); t.setRemainingDuration(d); t.setPlannedDuration(d)
    t.setActivityType(ActivityType.TASK_DEPENDENT); t.setCalendar(cal)
    t.setPercentCompleteType(PercentCompleteType.DURATION)
    if alap: t.setConstraintType(ConstraintType.AS_LATE_AS_POSSIBLE)
    return t

a = task("A1000", 5)
b = task("A1010", 3, alap=True)
c = task("A1020", 10)

def link(x, y):
    y.addPredecessor(Relation.Builder().predecessorTask(x).successorTask(y)
                     .type(RelationType.FINISH_START).lag(Duration.getInstance(0, TimeUnit.HOURS)))

link(a, b); link(a, c)
PrimaveraScheduler().schedule(p, start)
print("after 1st schedule: A1010 (ALAP) duration =", b.getDuration(), "| A1000 duration =", a.getDuration())
PrimaveraScheduler().schedule(p, start)   # raises CpmException: Task has no duration value

Expected

Scheduling leaves an activity's Duration as it was, so a schedule can be run again (or written and read back) without first restoring durations.

Scale

On 30 real P6 schedules, 114 activities on 14 of the 16 schedules that have ALAP activities lost their Duration. Every one was ALAP, and no schedule without ALAP activities lost any.

Possible cause

From reading master (I haven't tested a fix): the ALAP early-dates path ends with task.setDuration(calculateAtCompletionDuration(task)) without setting the activity's actual duration first. For an activity with no actual start, calculateAtCompletionDuration then falls through to getWork(task.getActualStart(), ...) with a null start. The non-ALAP path sets the actual duration (0 when not started) before the same call, so it returns the remaining duration instead. The code looks the same in 16.11.0, but I've only run the repro on 16.10.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0