Handling missing fields when using Python lamda's
<p>I have this rethinkDB query which basically returns the documents which "basicConstraints" fields that start with "CA:FA".</p>

<p>However in some of my documents the "basicConstraints" field does not exist. </p>

<pre><code>q = r.db('scanafi').table(active_table) \
.concat_map(lambda doc: doc["certificates"]\
.concat_map(lambda x: x["parsed_certificate"]["X509 extensions"])\
    .filter(lambda x: x["basicConstraints"]
.match("^CA:FA"))) \
.run()
</code></pre>

<p>How can I also include all of the documents which contain this missing field in my query?</p>

<p>It seems that your <code>x</code> doesn't have methods like a regular python dict (I'm not familiar with rethinkdb).  You could just use a real function here, with a try/except clause:</p>

<pre><code>def basic_constraints(x):
    try:
        return x["basicConstraints"]
    except:  # find out what the actual exception is and put that here
        return True

q = r.db('scanafi').table(active_table) \
.concat_map(lambda doc: doc["certificates"]\
.concat_map(lambda x: x["parsed_certificate"]["X509 extensions"])\
    .filter(basic_constraints)
.match("^CA:FA"))) \
.run()## Heading ##
</code></pre>

python lambda rethinkdb rethinkdb-python