Add new device saves this device when given its localhost address

Open
#16,074 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
networking

Research direction

Start with NetworkClient.discover_from_address in kolibri/core/discovery/utils/network/client.py and the NetworkClientTestCase tests in kolibri/core/discovery/test/test_network_utils.py; the issue provides a passing reproduction for localhost:8000. Trace how discovered and saved devices are checked against the current instance ID. Done when all acceptance criteria pass, including rejecting the current instance across ports and schemes while adding a different Kolibri in one request.

Written by the indexing model from the issue text.

Description

APP: Device bug DEV: backend

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: develop

Observed behavior

  • Add new device with localhost:8000, on a device serving on port 8000, saves this device at http://localhost:8000/.
  • 127.0.0.1:8000 and the LAN address get the field error "Could not connect to this device".
  • NetworkClient.discover_from_address skips only the URLs get_urls() returns, and localhost is never one of them: client.py#L154-L157.
  • Once saved, the same address is returned from the saved device without a request: client.py#L109-L125.

Expected behavior

An address that answers /api/public/info/ with this device's own instance ID is refused like 127.0.0.1:8000.

User-facing consequences

Select device lists this device as a source for its own channel and facility imports.

Steps to reproduce

  1. Sign in as a super admin on a device serving on port 8000.
  2. Device > Channels > Import > Local network or internet > Continue > Add new device.
  3. Enter localhost:8000 as Full network address, fill in Name, select Add.
  4. Select device shows the new device.

The same result without a browser, in kolibri/core/discovery/test/test_network_utils.py's NetworkClientTestCase; this passes on develop:

@mock.patch.object(
    requests.Session, "request", mock_happy_request("http://localhost:8000/")
)
def test_discover_from_address__returns_own_instance_at_localhost(self):
    own_instance_id = InstanceIDModel.get_or_create_current_instance()[0].id
    with mock.patch.dict(mock_device_info, {"instance_id": own_instance_id}):
        client = NetworkClient.discover_from_address("localhost:8000")
    self.assertEqual(client.base_url, "http://localhost:8000/")

Context

  • Kolibri develop at 758605b764, Linux, no URL_PATH_PREFIX.
  • The browser steps ran on #16072's branch at 2d9c5f6274, which returns the same result as develop for this address.

Acceptance Criteria

  • Add new device with localhost:<port> of this device shows "Could not connect to this device" and saves nothing.
  • A saved device whose instance ID is this device's is not returned by discover_from_address.
  • When the entered address reports this device's instance ID, no device at another port or scheme of that host is saved in its place.
  • A different Kolibri at an address get_urls() does not list is still added in one request.

AI usage

Written by rtibblesbot, an LLM-based coding agent running Claude Code, from its browser QA of #16072 and a run of discover_from_address on develop.

Dominant language
Python
Stars
1.2k
Forks
1.1k
Avg merge
2d 9h
Merged PRs (30d)
87

Getting set up

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.

More from learningequality/kolibri

All issues in learningequality/kolibri

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.