openedx / openedx/edx-notes-api

package import inappropriate

Open
#343 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
16
Forks
63
Avg merge
22h 48m
Merged PRs (30d)
8

Description

Few imports have been made under a condition, but they are used anywhere in the views file. If the condition is not satisfied, it will throw an error, such as "variable is not defined."

notesapi/v1/views.py (line 18 to 30)

if not settings.ES_DISABLED:
    from elasticsearch_dsl import Search
    from elasticsearch_dsl.connections import connections
    from django_elasticsearch_dsl_drf.filter_backends import DefaultOrderingFilterBackend, HighlightBackend
    from django_elasticsearch_dsl_drf.constants import (
        LOOKUP_FILTER_TERM,
        LOOKUP_QUERY_IN,
        SEPARATOR_LOOKUP_COMPLEX_VALUE,
    )
    from notesapi.v1.search_indexes.paginators import NotesPagination as ESNotesPagination
    from notesapi.v1.search_indexes.backends import CompoundSearchFilterBackend, FilteringFilterBackend
    from notesapi.v1.search_indexes.serializers import NoteDocumentSerializer as NotesElasticSearchSerializer

but used anywhere without any conditions.
example LOOKUP_FILTER_TERM has been imported under ES_DISABLED condition but used without any prior condition.
in this, if we disable the ES_DISABLED = True then the project will throw errors.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read notesapi/v1/views.py lines 18-30 and trace each conditionally imported name, including LOOKUP_FILTER_TERM, at its usages. Reproduce the failure with ES_DISABLED=True and verify that disabling Elasticsearch no longer raises undefined-name errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, elasticsearch, python
Domain
backend, search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.