[tracker/sam/tracker-resource-avoid-invalid-sparql] libtracker-sparql: Warn when serializing a resource with 0 properties



commit 3c23ffa5eac724830aa4f3f70eba2e97fe13c3fa
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Aug 26 15:58:48 2019 +0300

    libtracker-sparql: Warn when serializing a resource with 0 properties
    
    We can't describe an RDF resource without knowing at least one property
    about it. If we have 0 properties, it is due to a programmer error or
    a bug. We now warn in this case, where previously we would just generate
    invalid SPARQL and trigger an error further down the line.

 src/libtracker-sparql/tracker-resource.c | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 9c9fd53aa..9c504272c 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -1440,6 +1440,14 @@ generate_sparql_insert_pattern (TrackerResource    *resource,
        const GValue *value;
        gboolean had_property = FALSE;
 
+       /* If the resource has no properties, this function would generate invalid
+        * SPARQL. */
+       if (g_hash_table_size(priv->properties) == 0) {
+               g_warning("Resource with identifier %s has no properties. Unable to "
+                         " serialize to SPARQL.", priv->identifier);
+               return;
+       }
+
        /* First, emit any sub-resources. */
        g_hash_table_foreach (priv->properties, generate_sparql_relation_inserts_foreach, data);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]