Skip to content

Commit 4b289f0

Browse files
committed
don't rename repos from client reports
repo names are set at creation via get_or_create_repo and should not be overwritten by subsequent client reports. the admin may have renamed the repo in the web ui, and mixed client versions can report different name formats for the same mirror url, causing unique constraint errors.
1 parent 0e392a0 commit 4b289f0

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

reports/tests/test_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,35 @@ def test_process_repo_json_rpm(self):
227227
# RPM priority is negated
228228
self.assertEqual(priority, -99)
229229

230+
def test_process_repo_no_rename_on_existing_mirror(self):
231+
"""Repo found by mirror URL should keep its original name.
232+
233+
Repo names are set at creation and should not be overwritten by
234+
client reports — the admin may have renamed the repo in the UI.
235+
"""
236+
repo, _ = process_repo(
237+
r_type=Repository.RPM,
238+
r_name='Zabbix Official Repository - x86_64 x86_64',
239+
r_id='zabbix',
240+
r_priority=-99,
241+
urls=['https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64'],
242+
arch='x86_64',
243+
)
244+
self.assertEqual(repo.name, 'Zabbix Official Repository - x86_64 x86_64')
245+
246+
# updated client reports same URL with corrected name
247+
repo2, _ = process_repo(
248+
r_type=Repository.RPM,
249+
r_name='Zabbix Official Repository - x86_64',
250+
r_id='zabbix',
251+
r_priority=-99,
252+
urls=['https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64'],
253+
arch='x86_64',
254+
)
255+
# should return the same repo, name unchanged
256+
self.assertEqual(repo2.id, repo.id)
257+
self.assertEqual(repo2.name, 'Zabbix Official Repository - x86_64 x86_64')
258+
230259

231260
@override_settings(
232261
CELERY_TASK_ALWAYS_EAGER=True,

reports/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ def process_repo(r_type, r_name, r_id, r_priority, urls, arch):
258258
if r_id and repository.repo_id != r_id:
259259
repository.repo_id = r_id
260260

261-
if r_name and repository.name != r_name:
262-
repository.name = r_name
263-
264261
for url in unknown:
265262
Mirror.objects.create(repo=repository, url=url.rstrip('/'))
266263

0 commit comments

Comments
 (0)