Skip to content

Disable /learn API method by default#843

Merged
juhoinkinen merged 9 commits into
mainfrom
default-disable-learn-function
Aug 4, 2025
Merged

Disable /learn API method by default#843
juhoinkinen merged 9 commits into
mainfrom
default-disable-learn-function

Conversation

@juhoinkinen

@juhoinkinen juhoinkinen commented Apr 1, 2025

Copy link
Copy Markdown
Member

The learn functionality is rarely used, so it is best to be disabled by default for API requests.

This pull request introduces a new feature that restricts learning operations on projects unless explicitly enabled with allow_learn project config parameter.

Adds a new 403 response in the OpenAPI specification for trying to access the /v1/<project>/learn when the project is not configured to allow this.

@juhoinkinen juhoinkinen added this to the 1.4 milestone Apr 1, 2025
@codecov

codecov Bot commented Apr 1, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (38f5e8a) to head (39d2a8c).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #843      +/-   ##
==========================================
+ Coverage   99.63%   99.64%   +0.01%     
==========================================
  Files          99       99              
  Lines        7350     7361      +11     
==========================================
+ Hits         7323     7335      +12     
+ Misses         27       26       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@osma

osma commented Apr 1, 2025

Copy link
Copy Markdown
Member

The existing visibility settings only affect the REST API. I think this could also be scoped the same way; the CLI probably shouldn't care about this setting.

@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2025

Copy link
Copy Markdown

@juhoinkinen juhoinkinen requested a review from Copilot April 1, 2025 12:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR disables the learn functionality by default unless explicitly enabled via the project configuration.

  • Adds a configuration parameter "allow_learn" to control the learn functionality.
  • Updates tests for REST API, project configuration, and CLI to account for the learn functionality change.
  • Adjusts error handling in REST endpoints and the project learning method.

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_rest.py Adds a test case to ensure the REST learn functionality returns 403 when disabled
tests/test_project.py Updates the expected project count reflecting the new configuration change
tests/test_config.py Updates the expected count of project IDs to match the new project setup
tests/test_cli.py Adjusts commit add counts and completion results for the modified projects
annif/rest.py Introduces a new error response for disabled learning and handles OperationFailedException
annif/project.py Adds a conditional to check the allow_learn flag before invoking learning on the backend
Files not reviewed (2)
  • annif/openapi/annif.yaml: Language not supported
  • tests/projects.cfg: Language not supported

Comment thread annif/rest.py Outdated
corpus = _documents_to_corpus(body, project.subjects)
project.learn(corpus)
except OperationFailedException as err:
if str(err) == "Learning not enabled for project":

This comment was marked as off-topic.

Comment thread annif/rest.py Outdated
@juhoinkinen juhoinkinen marked this pull request as ready for review July 7, 2025 14:04
@juhoinkinen juhoinkinen requested a review from osma July 7, 2025 14:05
@juhoinkinen juhoinkinen changed the title WIP Default disable learn function Disable /learn API method by default Jul 8, 2025

@osma osma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested defining and using a new exception type for this case. Otherwise LGTM and can be merged!

Comment thread annif/project.py Outdated
Comment thread annif/rest.py Outdated
@sonarqubecloud

sonarqubecloud Bot commented Aug 4, 2025

Copy link
Copy Markdown

@juhoinkinen juhoinkinen merged commit 8a6f3cc into main Aug 4, 2025
14 checks passed
@juhoinkinen juhoinkinen deleted the default-disable-learn-function branch August 4, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants