Simple Event post /api/event 500 with geometry

I’m not sure if the bug I encountered is the same I tried to reproduce on play.

If you provide a geometry on the event payload, the api returns a 500 html page.
It seems a problem when the event is updated with that payload (creating is ok, it’s when you run for a second time the call that it fails)

On my server it’s a much older version (where there’s seem to have a compatibility layer for event.coordinate vs event.geometry) , but the problem is a NullPointerException on EventGeometryCheck :slight_smile:

java.lang.NullPointerException
	at org.hisp.dhis.dxf2.events.importer.shared.validation.EventGeometryCheck.check(EventGeometryCheck.java:58)
	at org.hisp.dhis.dxf2.events.importer.EventChecking$ValidationRunner.run(EventChecking.java:87)
	at org.hisp.dhis.dxf2.events.importer.update.validation.UpdateValidationFactory.check(UpdateValidationFactory.java:67)
	at org.hisp.dhis.dxf2.events.importer.EventManager.updateEvents(EventManager.java:189)
	at org.hisp.dhis.dxf2.events.importer.EventImporter.importAll(EventImporter.java:104)
	at org.hisp.dhis.dxf2.events.importer.EventServiceFacade.addEventsJson(EventServiceFacade.java:101)
	at org.hisp.dhis.dxf2.events.event.JacksonEventService.addEventsJson(JacksonEventService.java:205)

I don’t have access to the logs of the play so can’t confirm the problem.

const api = await dhis2.api();
try {
  const ou = await api.post("events", {
    events: [
      {
        program: "lxAQ7Zs9VYR",
        event: "IkPFV45y5jT",
        orgUnit: "U7yKrx2QVet",
        eventDate: "2024-04-24",
        status: "COMPLETED",
        attributeOptionCombo: "YqqFt4pRz9j",
        dataValues: [
          {
            dataElement: "vANAXwtLwcT",
            value: "12"
          }
        ],

        geometry: {
          type: "Point",
          coordinates: [2.4550449999999997, 6.3677616666666665]
        }
      }
    ]
  });
  return ou;
} catch (e) {
  return e;
}

Yeah, I understand the issue you could be facing, but the /api/events is a deprecated endpoint so even if there’s a bug in that older version it will not be of a major and prioritized importance; however, if we’re facing the same issue using the latest version and the new endpoint then it will most definitely be fixed.

You can read more about deprecated endpoints here: Tracker (deprecated) - DHIS2 Documentation

For the record, I understand the game at play but upgrading dhis2 instance is generally a long process, and that old version doesn’t have the tracker api.

For the sake of a future upgrade, I tried to replicate that

  • on 2.39 : I have an error about an invalid date “Month not valid [1,4,7,10], was given 9” while trying to specify the featureType on the program
  • on 2.40 : the redirection looks broken or it moved permanently https://play.dhis2.org/40 to https://play.dhis2.org/40.3.1/ and doesn’t update on the new patch. on 40.3.2 it seem to work
  • on 2.41 : seem to work
const eventPayload = {
  event: "A7vnB73x5Xw",
  status: "COMPLETED",
  program: "lxAQ7Zs9VYR",
  programStage: "dBwrot7S420",
  enrollment: "RHyovvxGd2F",
  orgUnit: "DiszpKrYNg8",
  orgUnitName: "Ngelehun CHC",
  occurredAt: "2024-04-01T00:00:00.000",
  storedBy: "android",
  followup: false,
  deleted: false,
  createdAt: "2018-04-12T16:05:16.957",
  updatedAt: "2024-06-03T11:01:00.363",
  updatedAtClient: "2024-06-03T10:53:16.184",
  attributeOptionCombo: "HllvX50cXC0",
  attributeCategoryOptions: "xYerKDKCefk",
  assignedUser: {},
  dataValues: [
    {
      dataElement: "vANAXwtLwcT",
      value: "4"
    },
    {
      dataElement: "sWoqcoByYmD",
      value: "true"
    },
    {
      dataElement: "Ok9OQpitjQr",
      value: "true"
    }
  ],
  notes: [],
  geometry: {
    type: "Point",
    coordinates: [2.4550449999999997, 6.3677616666666665]
  }
};

try {
  const api = await dhis2.api();
  const program = await api.get("programs/lxAQ7Zs9VYR");
  program.featureType = "POINT";
  await api.update("programs/lxAQ7Zs9VYR", program);
  return await api.post("tracker?async=false", { events: [eventPayload] });
} catch (exception) {
  debugger;
  return exception;
}
// event used as payload - created/updated by
// https://play.im.dhis2.org/stable-2-39-5/api/tracker/events/A7vnB73x5Xw.json