Strain Data Failure with LeafData

It’s getting confusing now, but let’s back-track one step first. LeafData is the software system built for Washington by MJ Freeway – who now calls themselves Akerna. It’s the same actors, with the same problems – on their third or fourth name (don’t forget MTech).

TL;DR

The Akerna/MJ Freeway/LeafData system in Washington was upgraded to version 1.37.5 on July 15th, 2019. That upgrade was intended to fix a lot of problems – including one of referential integrity. A result of this is that some growers cannot log new Plants into the system. A data lookup and mapping is failing as indicated by the database details in the error message.

Strain Data

In the $KERN/MJF/LD system there is the concept of a Strain, it’s really a Variety of the cannabis plant. Many other agriculture or horticulture groups say Variety but here, and cannabis in general, we use Strain.

This Variety information is not critical, nor required, to the regulation of the cannabis plant. However, $KERN/MJF/LD in their finite-wisdom has made it a critcal component. All Plants and Inventory Lots should have Strain.

In database speak, this creates a foreign key constraint to enforce referential integrity

Strain Data Failure

Here is the issue we continue to observe.

We can query the system, to see this Strain information. These are real values, we’ve just removed some identifying details.

GET /strains

{"created_at":"08\/07\/2019 05:26pm","updated_at":"08\/10\/2019 03:26pm","external_id":"","name":"MAC 1","deleted_at":null,"global_id":"STNASY"}

That Strain looks good right? And we have Inventory Lots attached to that Strain. So, lets convert into Plant type items, using the defined API call

POST /move_inventory_to_plants

{
	"global_inventory_id": "INCM0P8",
	"global_area_id": "AR31RM",
	"global_strain_id": "STNASY",
	"qty": 120
}

And the failure response, which we’ve formatted

{
    "error": true,
    "error_message": "",
    "validation_messages": "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
		(`wa_prod`.`plants`, CONSTRAINT `plants_strain_id_fk` FOREIGN KEY (`strain_id`)
		REFERENCES `strains` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) (
		SQL: insert into `plants` (`mme_id`, `user_id`, `batch_id`, `area_id`, `strain_id`, `origin`, `stage`, `updated_at`, `created_at`)
			values (1748, 1766, 22834935, 100216, 0, none, growing, 2019-08-10 15:36:35, 2019-08-10 15:36:35)
		)"
}

Notice here that the the value for the Strain ID column is 0. Of course, that’s not right. It appears their system canont lookup our strain ID of STNASY to the proper integer value for their database.

Also: