fluree / core

Fluree releases and public bug reports
0 stars 0 forks source link

`insert` is dropped if `where` result is empty, even if `insert` is non-dependent on `where` #46

Closed aaj3f closed 8 months ago

aaj3f commented 8 months ago

Description

In a scenario where an insert statement depends on ?bindings populated from a where solution result, it makes sense that the insert statement would be dropped if no ?bindings were generated.

However currently, if an insert statement is independent of any bindings from a where result set, the insert statement still appears to be dropped.

For example, the following transaction:

{
    "@context": "https://ns.flur.ee",
    "ledger": "insert-delete-bug",
    "where": [["ex:andrew", "schema:description", "?o"]],
    "delete": {
        "@id": "ex:andrew",
        "schema:description": "?o"
    },
    "insert": [
        {
            "@id": "ex:andrew",
            "schema:description": "He's great. The core team *definitely* doesn't resent him for all the bug tickets he creates."
        }
    ]
}

Obviously the delete statement depends on the result of ?o, and so reasonably if no data matching ["ex:andrew", "schema:description", "?o"] exists, then no delete instructions should follow.

However the insert statement is independent of any ?bindings being produced from the result of the where execution, and we should expect the insert statement to execute regardless. Currently, however, it does not.

Recreation steps

NOTE: One part of the create transaction seems unnecessary, but currently we can't query for a property in the where clause if the property hasn't yet been instantiated with some data in a previous transaction, hence the need to include a random node with a schema:description value.

Create txn:

{
    "@context": "https://ns.flur.ee",
    "ledger": "insert-delete-bug",
    "insert": [
        {
            "@id": "ex:andrew",
            "schema:name": "Andrew"
        },
        {
            "@id": "ex:random",
            "schema:description": "Unfortunately I need to have added the property, 'schema:description' already for the next transaction to work... we should change that eventually."
        }
    ]
}

Buggy transaction that drops insert:

{
    "@context": "https://ns.flur.ee",
    "ledger": "insert-delete-bug",
    "where": [["ex:andrew", "schema:description", "?o"]],
    "delete": {
        "@id": "ex:andrew",
        "schema:description": "?o"
    },
    "insert": [
        {
            "@id": "ex:andrew",
            "schema:description": "He's great. The core team *definitely* doesn't resent him for all the bug tickets he creates."
        }
    ]
}