Skip to content

Commit f16b471

Browse files
committed
[CHANGE] Use pk instead of id when referring to the primary key
1 parent 8503519 commit f16b471

10 files changed

Lines changed: 36 additions & 35 deletions

File tree

‎.github/workflows/automated-checks.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Tests
33
env:
44
COVERAGE_DATABASE_VERSION: mariadb:10.11
55
COVERAGE_PYTHON_VERSION: 3.12
6-
NODE_VERSION: 24 # [LTS] End of Life: 30 Apr 2028 (https://endoflife.date/nodejs)
6+
NODE_VERSION: 26 # [LTS] End of Life: 30 Apr 2029 (https://endoflife.date/nodejs)
77
REDIS_VERSION: latest
88

99
on:

‎.github/workflows/release.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ jobs:
5858
token: ${{ secrets.GITHUB_TOKEN }}
5959
# The name of the file(s) to upload
6060
files: |
61-
dist/*
61+
dist/*.tar.gz
62+
dist/*.whl

‎.pre-commit-config.yaml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Set the default language versions for the hooks
77
default_language_version:
88
python: python3 # Force all Python hooks to use Python 3
9-
node: 24.14.0 # Force all Node hooks to use this specific Node version
9+
node: 26.3.0 # Force all Node hooks to use this specific Node version
1010

1111
# https://pre-commit.ci/
1212
ci:
@@ -68,7 +68,7 @@ repos:
6868
name: Check for large files
6969
description: Check for large files that were added to the repository.
7070
args:
71-
- --maxkb=1000
71+
- --maxkb=2048 # 2 MB
7272

7373
- id: detect-private-key
7474
name: Detect private key
@@ -120,8 +120,10 @@ repos:
120120
name: End of file fixer
121121
description: Ensure that files end with a newline.
122122

123-
- repo: https://github.com/eslint/eslint
124-
rev: 9089853a593d6c7c0f11367da08a829e0ddfe092 # frozen: v10.6.0
123+
# - repo: https://github.com/eslint/eslint
124+
# rev: 9089853a593d6c7c0f11367da08a829e0ddfe092 # frozen: v10.6.0
125+
- repo: https://github.com/pre-commit/mirrors-eslint
126+
rev: 8763fc929b6232999d541a3d8eb49965a6b71afb # frozen: v10.6.0
125127
hooks:
126128
- id: eslint
127129
name: ESLint

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Section Order:
5353
5454
### Changed
5555

56+
- Use `pk` instead of `id` when referring to the primary key of a model instance, since `id` is not guaranteed to be the primary key in Django.
5657
- Migrated to Alliance Auth proxy models for `Permission`, `User` and `Group`
5758

5859
## [5.0.1] - 2026-07-07

‎sovtimer/models.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ def bulk_get_or_create_from_esi(
8080
:rtype: dict[int, Alliance]
8181
"""
8282

83-
existing_alliances = cls.objects.filter(alliance_id__in=alliance_ids)
84-
existing_alliance_ids = set(
85-
existing_alliances.values_list("alliance_id", flat=True)
86-
)
83+
existing_alliances = cls.objects.filter(pk__in=alliance_ids)
84+
existing_alliance_ids = set(existing_alliances.values_list("pk", flat=True))
8785

8886
alliances_to_create = set(alliance_ids) - existing_alliance_ids
8987

@@ -118,9 +116,9 @@ def bulk_get_or_create_from_esi(
118116
created_alliances = cls.objects.bulk_create(new_alliances)
119117

120118
# Combine existing and newly created alliances into a single dictionary
121-
all_alliances = {
122-
alliance.alliance_id: alliance for alliance in existing_alliances
123-
} | {alliance.alliance_id: alliance for alliance in created_alliances}
119+
all_alliances = {alliance.pk: alliance for alliance in existing_alliances} | {
120+
alliance.pk: alliance for alliance in created_alliances
121+
}
124122

125123
return all_alliances
126124

‎sovtimer/tasks.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def update_sov_structures( # pylint: disable=too-many-locals
216216

217217
# Fetch solar systems from the database
218218
solar_systems = {
219-
ss.id: ss for ss in SolarSystem.objects.filter(id__in=solar_system_ids)
219+
ss.id: ss for ss in SolarSystem.objects.filter(pk__in=solar_system_ids)
220220
}
221221

222222
esi_structure_ids = set() # Track structure IDs from ESI to avoid duplicates

‎sovtimer/tests/test_models.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def test_returns_all_alliances_when_all_ids_exist(
139139
"""
140140

141141
mock_existing_alliances = [
142-
Alliance(alliance_id=1, name="Alliance 1"),
143-
Alliance(alliance_id=2, name="Alliance 2"),
142+
Alliance(pk=1, name="Alliance 1"),
143+
Alliance(pk=2, name="Alliance 2"),
144144
]
145145
mock_qs = MagicMock()
146146
mock_qs.__iter__.return_value = iter(mock_existing_alliances)
@@ -154,7 +154,7 @@ def test_returns_all_alliances_when_all_ids_exist(
154154
self.assertEqual(len(result), 2)
155155
self.assertEqual(result[1].name, "Alliance 1")
156156
self.assertEqual(result[2].name, "Alliance 2")
157-
mock_filter.assert_called_once_with(alliance_id__in={1, 2})
157+
mock_filter.assert_called_once_with(pk__in={1, 2})
158158
mock_bulk_create.assert_not_called()
159159
mock_get_alliance.assert_not_called()
160160

@@ -178,7 +178,7 @@ def test_creates_new_alliances_when_some_ids_do_not_exist(
178178
"""
179179

180180
mock_existing_alliances = [
181-
Alliance(alliance_id=1, name="Alliance 1"),
181+
Alliance(pk=1, name="Alliance 1"),
182182
]
183183
mock_qs = MagicMock()
184184
mock_qs.__iter__.return_value = iter(mock_existing_alliances)
@@ -192,8 +192,8 @@ def test_creates_new_alliances_when_some_ids_do_not_exist(
192192
mock_get_alliance.side_effect = [a2, a3]
193193

194194
mock_bulk_create.return_value = [
195-
Alliance(alliance_id=2, name="Alliance 2"),
196-
Alliance(alliance_id=3, name="Alliance 3"),
195+
Alliance(pk=2, name="Alliance 2"),
196+
Alliance(pk=3, name="Alliance 3"),
197197
]
198198

199199
result = Alliance.bulk_get_or_create_from_esi(
@@ -204,7 +204,7 @@ def test_creates_new_alliances_when_some_ids_do_not_exist(
204204
self.assertEqual(result[1].name, "Alliance 1")
205205
self.assertEqual(result[2].name, "Alliance 2")
206206
self.assertEqual(result[3].name, "Alliance 3")
207-
mock_filter.assert_called_once_with(alliance_id__in={1, 2, 3})
207+
mock_filter.assert_called_once_with(pk__in={1, 2, 3})
208208
mock_get_alliance.assert_any_call(alliance_id=2, force_refresh=False)
209209
mock_get_alliance.assert_any_call(alliance_id=3, force_refresh=False)
210210
mock_bulk_create.assert_called_once()
@@ -239,7 +239,7 @@ def test_skips_creation_when_esi_returns_no_data(
239239
)
240240

241241
self.assertEqual(len(result), 0)
242-
mock_filter.assert_called_once_with(alliance_id__in={1})
242+
mock_filter.assert_called_once_with(pk__in={1})
243243
mock_get_alliance.assert_called_once_with(alliance_id=1, force_refresh=False)
244244
mock_bulk_create.assert_not_called()
245245

‎sovtimer/tests/test_tasks.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_processes_structure_with_default_vulnerability(
144144
]
145145

146146
mock_bulk_get_or_create.return_value = {
147-
2001: Alliance(alliance_id=2001, name="Alliance 2001")
147+
2001: Alliance(pk=2001, name="Alliance 2001")
148148
}
149149
mock_solar_system_filter.return_value = [SolarSystem(id=3001)]
150150
mock_bulk_create.return_value = None
@@ -157,7 +157,7 @@ def test_processes_structure_with_default_vulnerability(
157157
mock_bulk_get_or_create.assert_called_once_with(
158158
alliance_ids={2001}, force_refresh=False
159159
)
160-
mock_solar_system_filter.assert_called_once_with(id__in={3001})
160+
mock_solar_system_filter.assert_called_once_with(pk__in={3001})
161161
mock_bulk_create.assert_called_once()
162162
created = mock_bulk_create.call_args[0][0]
163163
self.assertEqual(len(created), 1)

‎sovtimer/tests/test_views.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ def test_dashboard_data_includes_active_campaigns(
147147

148148
constellation = MagicMock()
149149
constellation.name = "Constellation A"
150-
constellation.id = 7002
150+
constellation.pk = 7002
151151
region = MagicMock()
152152
region.name = "Region A"
153-
region.id = 7001
153+
region.pk = 7001
154154
constellation.region = region
155155
solar_system.constellation = constellation
156156
structure.solar_system = solar_system
@@ -216,7 +216,7 @@ def test_dashboard_data_handles_missing_vulnerability_levels(
216216
constellation.name = "Constellation B"
217217
region = MagicMock()
218218
region.name = "Region B"
219-
region.id = 7003
219+
region.pk = 7003
220220
constellation.region = region
221221
solar_system.constellation = constellation
222222
structure.solar_system = solar_system
@@ -288,10 +288,10 @@ def test_campaign_status_is_upcoming_when_within_timeframe(
288288

289289
constellation = MagicMock()
290290
constellation.name = "Constellation U"
291-
constellation.id = 7004
291+
constellation.pk = 7004
292292
region = MagicMock()
293293
region.name = "Region U"
294-
region.id = 7005
294+
region.pk = 7005
295295
constellation.region = region
296296
solar_system.constellation = constellation
297297
structure.solar_system = solar_system
@@ -354,7 +354,7 @@ def test_sets_attackers_progress_when_previous_progress_is_higher(
354354
constellation.name = "Constellation X"
355355
region = MagicMock()
356356
region.name = "Region X"
357-
region.id = 7006
357+
region.pk = 7006
358358
constellation.region = region
359359
solar_system.constellation = constellation
360360
structure.solar_system = solar_system

‎sovtimer/views.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ def dashboard_data( # pylint: disable=too-many-statements too-many-locals
102102

103103
# Defender
104104
defender_name = alliance.name
105-
defender_url = dotlan_alliance_url(eve_obj=alliance.alliance_id)
106-
defender_logo_url = alliance_logo_url(alliance_id=alliance.alliance_id, size=32)
105+
defender_url = dotlan_alliance_url(eve_obj=alliance.pk)
106+
defender_logo_url = alliance_logo_url(alliance_id=alliance.pk, size=32)
107107
defender_name_html = (
108108
f'<a href="{defender_url}" target="_blank" rel="noopener noreferer">'
109109
f'<img class="aa-sovtimer-entity-logo-left me-2" src="{defender_logo_url}" '
110110
f'alt="{defender_name}">{defender_name}</a>'
111111
)
112112

113113
# Region / System / Constellation URLs and HTML (compute region_url once)
114-
region_url = dotlan_region_url(eve_obj=region.id)
114+
region_url = dotlan_region_url(eve_obj=region.pk)
115115
campaign_system_name = solar_system.name
116116
solar_system_url = f"{region_url}/{campaign_system_name}"
117117
solar_system_name_html = f'<a href="{solar_system_url}" target="_blank" rel="noopener noreferer">{campaign_system_name}</a>'
@@ -161,8 +161,7 @@ def dashboard_data( # pylint: disable=too-many-statements too-many-locals
161161
f'title="{title}" data-bs-tooltip="aa-sovtimer">{icon_name}</i>'
162162
)
163163

164-
constellation_id = constellation.id
165-
zkb_href = f"https://zkillboard.com/constellation/{constellation_id}/"
164+
zkb_href = f"https://zkillboard.com/constellation/{constellation.pk}/"
166165
zkb_icon = f'<img src="{static("sovtimer/images/zkillboard.png")}" alt="zKillboard">'
167166
constellation_killboard_link = (
168167
f'<a href="{zkb_href}" target="_blank" rel="noopener noreferer" '

0 commit comments

Comments
 (0)