Get_movies_faceted :: pipeline=[]

:warning:ATTENTION:warning:

There is a second initialization of the variable pipeline after the TODO comment that is causing a loss of code provoking unwanted results:

# TODO: Faceted Search
# Add the necessary stages to the pipeline variable in the correct order.
pipeline = []

It must be commented or deleted as to keep the $match filter definition some lines above:

if "cast" in filters:
    pipeline.extend([{
        "$match": {"cast": {"$in": filters.get("cast")}}
    }, {
        "$sort": {sort_key: DESCENDING}
    }])
else:
    raise AssertionError("No filters to pass to faceted search!")

Jaime Rozo

Hi @jhrozo,

I understand your concern. But the motive of putting pipeline = [] variable is not to confuse/reset the variable. It is used to append more pipeline stages in addition to $match and $sort stage.

As it is already mentioned in the file just above the TODO line:

The pipeline is a Python array, so you can use append() or extend() to
complete this task.

I hope it helps!

Kanika

I have to agree with @jhrozo on this one. Declaring the pipeline variable a second time does clean out the existing values. Even after appending/extending the ‘new’ pipeline variable, the original payload from the filters variable is gone. While this is only slightly confusing, the pipeline declaration after the TODO should probably be tossed. The instructions are clear enough.

1 Like

Hi Kanika,
I got your point but I believe you did not get my point about re-initializing the variable pipeline. Basically, what I am pointing to is:

variable = [ ]
variable.extend([‘some data’])
print(variable)

variable = [ ]
variable.extend([‘more data’])
print(variable)

The same situation occurs in the get_movies_faceted function but with the pipeline variable. The second print will only show ['more data´] as the list ['some data´] is already gone after the reset of the variable.

Jaime.

1 Like

Hi @jhrozo,

You are right.
This is a side effect of multiple different labs in the same method.
We will fix this.

Thanks for flagging.

N.

2 Likes