OpenTreeMap / otm-core

OpenTreeMap is a collaborative platform for crowdsourced tree inventory, ecosystem services calculations, urban forestry analysis, and community engagement.
www.opentreemap.org
Other
188 stars 87 forks source link

API - When saving model that has plot alerts, alert IDs are not returned #1534

Closed lliss closed 10 years ago

lliss commented 10 years ago

To reproduce:

lliss commented 10 years ago

Here a sample request I made:

{"latest_update":{"user_id":1,"ref":null,"current_value":"Unresolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Resolved","created":"2014-08-11 01:13:08.876537+00:00","field":"udf:Status","model":"udf:113"},"has_tree":true,"recent_activity":[[{"username":"administrator","id":1},"2014-08-11T01:13:08.876Z",[{"user_id":1,"ref":null,"current_value":"Unresolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Resolved","created":"2014-08-11 01:13:08.876537+00:00","field":"udf:Status","model":"udf:113"},{"user_id":1,"ref":null,"current_value":"Resolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Unresolved","created":"2014-08-11 01:09:26.370644+00:00","field":"udf:Status","model":"udf:113"},{"user_id":1,"ref":null,"current_value":"Unresolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Resolved","created":"2014-08-11 00:24:12.883409+00:00","field":"udf:Status","model":"udf:113"},{"user_id":1,"ref":null,"current_value":"Resolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Unresolved","created":"2014-08-10 15:29:23.571152+00:00","field":"udf:Status","model":"udf:113"},{"user_id":1,"ref":null,"current_value":"Unresolved","instance_id":41,"requires_auth":false,"model_id":443,"action":3,"previous_value":"Resolved","created":"2014-08-10 15:23:46.577128+00:00","field":"udf:Status","model":"udf:113"}]]],"currency_symbol":"$","basis":{"plot":{"n_objects_discarded":0,"n_objects_used":1}},"title":"Mango","progress_messages":["Add a photo"],"benefits":{"plot":{"co2":{"currency_saved":"$0","name":"co2","label":"Carbon dioxide removed","value":"7.8","unit":"lbs\/year","currency":0.02601745549333333,"unit-name":"eco"},"energy":{"currency_saved":"$0","name":"energy","label":"Energy conserved","value":"2.3","unit":"kwh\/year","currency":0.3345017816666667,"unit-name":"eco"},"co2storage":{"currency_saved":"$0","name":"co2storage","label":"Carbon dioxide stored to date","value":"6.3","unit":"lbs","currency":0.02109766666666667,"unit-name":"eco"},"airquality":{"currency_saved":"$0","name":"airquality","label":"Air quality improved","value":"-0.0","unit":"lbs\/year","currency":0.1139869376066666,"unit-name":"eco"},"stormwater":{"currency_saved":"$0","name":"stormwater","label":"Stormwater filtered","value":"32.6","unit":"gal\/year","currency":0.3258121974666667,"unit-name":"eco"}}},"plot":{"id":444634,"udf:Powerlines Overhead":null,"owner_orig_id":null,"udf:Sidewalk Damage":null,"address_street":"","address_city":"","feature_type":"Plot","udf:Tree Location ":null,"address_zip":"","udf:Stewardship":[{"id":444,"Action":"Enlarging the Planting Area","Date":"2014-08-08 00:00:00"},{"id":445,"Action":"Adding a Guard","Date":"2014-08-08 00:00:00"},{"id":446,"Action":"Removing a Guard","Date":"2014-08-08 00:00:00"},{"id":447,"Action":"Herbaceous Planting","Date":"2014-08-08 00:00:00"}],"readonly":false,"udf:Alerts":[{"Action Needed":"Herbaceous Planting","id":443,"Date Noticed":"2036-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Adding a Guard","id":438,"Date Noticed":"2034-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Adding a Guard","id":439,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Adding a Guard","id":440,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Adding a Guard","id":441,"Date Noticed":"2034-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Adding a Guard","id":442,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"}],"geom":{"y":33.95816914781239,"x":-118.5376739501954,"srid":4326},"width":null,"instance":41,"length":null,"mapfeature_ptr":444634},"feature_type":"Plot","feature":{"id":444634,"udf:Powerlines Overhead":null,"owner_orig_id":null,"udf:Sidewalk Damage":null,"address_street":"","address_city":"","feature_type":"Plot","udf:Tree Location ":null,"address_zip":"","udf:Stewardship":[{"id":444,"Date":"2014-08-08 00:00:00","Action":"Enlarging the Planting Area"},{"id":445,"Date":"2014-08-08 00:00:00","Action":"Adding a Guard"},{"id":446,"Date":"2014-08-08 00:00:00","Action":"Removing a Guard"},{"id":447,"Date":"2014-08-08 00:00:00","Action":"Herbaceous Planting"}],"readonly":false,"udf:Alerts":[{"Action Needed":"Herbaceous Planting","id":443,"Date Noticed":"2036-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Adding a Guard","id":438,"Date Noticed":"2034-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Adding a Guard","id":439,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Adding a Guard","id":440,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Adding a Guard","id":441,"Date Noticed":"2034-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Adding a Guard","id":442,"Date Noticed":"2034-08-08 00:00:00","Status":"Resolved"}],"geom":{"y":33.95816914781239,"x":-118.5376739501954,"srid":4326},"width":null,"instance":41,"length":null,"mapfeature_ptr":444634},"photos":[],"progress_percent":75,"upload_photo_endpoint":"\/latreemap\/plots\/444634\/tree\/474378\/photo","tree":{"id":474378,"species":{"fact_sheet":"http:\/\/selectree.calpoly.edu\/treedetail.lasso?rid=922","max_height":800,"bloom_period":"winter\/spring","instance":41,"flower_conspicuous":true,"common_name":"Mango","scientific_name":"Mangifera indica","cultivar":null,"plant_guide":null,"max_dbh":200,"wildlife_value":false,"other":null,"id":11203,"fall_conspicuous":false,"palatable_human":true,"gender":null,"genus":"Mangifera","fruit_period":"spring","species":"indica","otm_code":"","native_status":false},"canopy_height":null,"udf:Funded By":null,"udf:Planted By":null,"plot":444634,"udf:Stewardship":[{"id":422,"Action":"Watering","Date":"2014-08-08 00:00:00"},{"id":423,"Action":"Pruning","Date":"2014-08-08 00:00:00"},{"id":424,"Action":"Mulching, Adding Compost or Amending Soil","Date":"2014-08-08 00:00:00"},{"id":425,"Action":"Removing Debris or Trash","Date":"2014-08-08 00:00:00"}],"date_planted":null,"readonly":false,"date_removed":null,"udf:Alerts":[{"Action Needed":"Watering","id":418,"Date Noticed":"2014-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Mulching, Adding Compost or Amending Soil","id":420,"Date Noticed":"2014-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Removing Debris or Trash","id":421,"Date Noticed":"2014-08-08 00:00:00","Status":"Unresolved"},{"Action Needed":"Pruning","id":419,"Date Noticed":"2014-08-08 00:00:00","Status":"Resolved"},{"Action Needed":"Removing Debris or Trash","id":436,"Date Noticed":"2035-08-08 00:00:00","Status":"Resolved"}],"height":3,"instance":41,"diameter":2}}
lliss commented 10 years ago

And here is the response:

{
    "progress_messages": ["Add a photo"],
    "benefits": {
        "plot": {
            "co2storage": {
                "name": "co2storage",
                "value": "6.3",
                "label": "Carbon dioxide stored to date",
                "currency": 0.021097666666666667,
                "currency_saved": "$0",
                "unit": "lbs",
                "unit-name": "eco"
            },
            "energy": {
                "name": "energy",
                "value": "2.3",
                "label": "Energy conserved",
                "currency": 0.33450178166666666,
                "currency_saved": "$0",
                "unit": "kwh/year",
                "unit-name": "eco"
            },
            "co2": {
                "name": "co2",
                "value": "7.8",
                "label": "Carbon dioxide removed",
                "currency": 0.026017455493333334,
                "currency_saved": "$0",
                "unit": "lbs/year",
                "unit-name": "eco"
            },
            "airquality": {
                "name": "airquality",
                "value": "-0.0",
                "label": "Air quality improved",
                "currency": 0.11398693760666663,
                "currency_saved": "$0",
                "unit": "lbs/year",
                "unit-name": "eco"
            },
            "stormwater": {
                "name": "stormwater",
                "value": "32.6",
                "label": "Stormwater filtered",
                "currency": 0.3258121974666667,
                "currency_saved": "$0",
                "unit": "gal/year",
                "unit-name": "eco"
            }
        }
    },
    "feature_type": "Plot",
    "title": "Mango",
    "plot": {
        "address_city": "",
        "udf:Alerts": [{
            "Action Needed": "Herbaceous Planting",
            "Date Noticed": "2036-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Unresolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Unresolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }],
        "feature_type": "Plot",
        "udf:Powerlines Overhead": null,
        "width": null,
        "owner_orig_id": null,
        "udf:Sidewalk Damage": null,
        "readonly": false,
        "mapfeature_ptr": 444634,
        "instance": 41,
        "geom": {
            "y": 33.95816914781239,
            "x": -118.53767395019537,
            "srid": 4326
        },
        "udf:Tree Location ": null,
        "length": null,
        "udf:Stewardship": [{
            "Action": "Enlarging the Planting Area",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Adding a Guard",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Removing a Guard",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Herbaceous Planting",
            "Date": "2014-08-08 00:00:00"
        }],
        "address_street": "",
        "id": 444634,
        "address_zip": ""
    },
    "basis": {
        "plot": {
            "n_objects_discarded": 0,
            "n_objects_used": 1
        }
    },
    "tree": {
        "plot": 444634,
        "diameter": 2.0,
        "date_planted": null,
        "readonly": false,
        "canopy_height": null,
        "id": 474378,
        "instance": 41,
        "udf:Stewardship": [{
            "Date": "2014-08-08 00:00:00",
            "Action": "Watering",
            "id": 422
        }, {
            "Date": "2014-08-08 00:00:00",
            "Action": "Pruning",
            "id": 423
        }, {
            "Date": "2014-08-08 00:00:00",
            "Action": "Mulching, Adding Compost or Amending Soil",
            "id": 424
        }, {
            "Date": "2014-08-08 00:00:00",
            "Action": "Removing Debris or Trash",
            "id": 425
        }],
        "date_removed": null,
        "udf:Alerts": [{
            "Status": "Unresolved",
            "Date Noticed": "2014-08-08 00:00:00",
            "Action Needed": "Watering",
            "id": 418
        }, {
            "Status": "Unresolved",
            "Date Noticed": "2014-08-08 00:00:00",
            "Action Needed": "Mulching, Adding Compost or Amending Soil",
            "id": 420
        }, {
            "Status": "Unresolved",
            "Date Noticed": "2014-08-08 00:00:00",
            "Action Needed": "Removing Debris or Trash",
            "id": 421
        }, {
            "Status": "Resolved",
            "Date Noticed": "2014-08-08 00:00:00",
            "Action Needed": "Pruning",
            "id": 419
        }, {
            "Status": "Resolved",
            "Date Noticed": "2035-08-08 00:00:00",
            "Action Needed": "Removing Debris or Trash",
            "id": 436
        }],
        "udf:Funded By": null,
        "height": 3.0,
        "species": {
            "scientific_name": "Mangifera indica",
            "otm_code": "",
            "flower_conspicuous": true,
            "common_name": "Mango",
            "plant_guide": null,
            "fall_conspicuous": false,
            "species": "indica",
            "instance": 41,
            "max_dbh": 200,
            "wildlife_value": false,
            "id": 11203,
            "fact_sheet": "http://selectree.calpoly.edu/treedetail.lasso?rid=922",
            "other": null,
            "native_status": false,
            "palatable_human": true,
            "max_height": 800,
            "fruit_period": "spring",
            "cultivar": null,
            "gender": null,
            "bloom_period": "winter/spring",
            "genus": "Mangifera"
        },
        "udf:Planted By": null
    },
    "feature": {
        "address_city": "",
        "udf:Alerts": [{
            "Action Needed": "Herbaceous Planting",
            "Date Noticed": "2036-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Unresolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Unresolved"
        }, {
            "Action Needed": "Adding a Guard",
            "Date Noticed": "2034-08-08 00:00:00",
            "Status": "Resolved"
        }],
        "feature_type": "Plot",
        "udf:Powerlines Overhead": null,
        "width": null,
        "owner_orig_id": null,
        "udf:Sidewalk Damage": null,
        "readonly": false,
        "mapfeature_ptr": 444634,
        "instance": 41,
        "geom": {
            "y": 33.95816914781239,
            "x": -118.53767395019537,
            "srid": 4326
        },
        "udf:Tree Location ": null,
        "length": null,
        "udf:Stewardship": [{
            "Action": "Enlarging the Planting Area",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Adding a Guard",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Removing a Guard",
            "Date": "2014-08-08 00:00:00"
        }, {
            "Action": "Herbaceous Planting",
            "Date": "2014-08-08 00:00:00"
        }],
        "address_street": "",
        "id": 444634,
        "address_zip": ""
    },
    "progress_percent": 75,
    "geoRevHash": "00ec53c4682d36f5c4359f4ae7bd7ba1",
    "photos": [],
    "latest_update": {
        "model_id": 443,
        "action": 3,
        "previous_value": "Unresolved",
        "requires_auth": false,
        "user_id": 1,
        "created": "2014-08-11 13:11:15.366399+00:00",
        "instance_id": 41,
        "field": "udf:Status",
        "current_value": "Resolved",
        "model": "udf:113",
        "ref": null
    },
    "currency_symbol": "$",
    "recent_activity": [
        [{
            "username": "administrator",
            "id": 1
        }, "2014-08-11T13:11:15.366Z", [{
            "model_id": 443,
            "action": 3,
            "previous_value": "Unresolved",
            "requires_auth": false,
            "user_id": 1,
            "created": "2014-08-11 13:11:15.366399+00:00",
            "instance_id": 41,
            "field": "udf:Status",
            "current_value": "Resolved",
            "model": "udf:113",
            "ref": null
        }, {
            "model_id": 443,
            "action": 3,
            "previous_value": "Resolved",
            "requires_auth": false,
            "user_id": 1,
            "created": "2014-08-11 01:13:08.876537+00:00",
            "instance_id": 41,
            "field": "udf:Status",
            "current_value": "Unresolved",
            "model": "udf:113",
            "ref": null
        }, {
            "model_id": 443,
            "action": 3,
            "previous_value": "Unresolved",
            "requires_auth": false,
            "user_id": 1,
            "created": "2014-08-11 01:09:26.370644+00:00",
            "instance_id": 41,
            "field": "udf:Status",
            "current_value": "Resolved",
            "model": "udf:113",
            "ref": null
        }, {
            "model_id": 443,
            "action": 3,
            "previous_value": "Resolved",
            "requires_auth": false,
            "user_id": 1,
            "created": "2014-08-11 00:24:12.883409+00:00",
            "instance_id": 41,
            "field": "udf:Status",
            "current_value": "Unresolved",
            "model": "udf:113",
            "ref": null
        }, {
            "model_id": 443,
            "action": 3,
            "previous_value": "Unresolved",
            "requires_auth": false,
            "user_id": 1,
            "created": "2014-08-10 15:29:23.571152+00:00",
            "instance_id": 41,
            "field": "udf:Status",
            "current_value": "Resolved",
            "model": "udf:113",
            "ref": null
        }]]
    ],
    "upload_photo_endpoint": "/latreemap/plots/444634/tree/474378/photo",
    "has_tree": true
}
maurizi commented 10 years ago

Looking at the response, both Alerts and Stewardship had an id for Tree, but not for Plot

lliss commented 10 years ago

Yeah. I did some more testing. The problem seems to be on plots, not trees.

andrewbt commented 10 years ago

@lliss @maurizi @jwalgran not sure how to test this one on release. If I knew the API endpoints and required payloads I could issue a request and see that the field is there. Otherwise I leave it to your judgement to put the "verified" label on or not for release.

lliss commented 10 years ago

The symptom of this problem is that if you add new stewardship or alert then save it, then edit the same tree again without closing the tree detail and edit the same alert, it would duplicate. You can try this workflow on one of the apps in prod. If everything works fine then you can be nearly certain it is working as expected.

andrewbt commented 10 years ago

Can't get any duplicated stewardships using the workflow described. Verifying.