1

I have this rethinkDB query which basically returns the documents which "basicConstraints" fields that start with "CA:FA".

However in some of my documents the "basicConstraints" field does not exist.

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()

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

2 Answers 2

0

It seems that your x 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:

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 ##
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick response. So I tried that but it throws the following error: .filter(lambda x: x["basicConstraints"] if "basicConstraints" in x else True TypeError: argument of type 'Var' is not iterable
0

You can write x.has_fields('basicConstraints').not().or_(x['basicConstraints'].match("^CA:FA")).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.