Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion structures/models/owners.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,11 @@ def _fetch_universe_infos_for_structures(
self, token: Token, structures: List[dict]
) -> bool:
count = 0
existing_names = dict(
self.structures.filter(
id__in=[s["structure_id"] for s in structures]
).values_list("id", "name")
)
for s in structures:
try:
structure_info_obj = (
Expand All @@ -654,7 +659,8 @@ def _fetch_universe_infos_for_structures(
self._report_esi_issue(
f"fetch structure #{s['structure_id']}", ex, token
)
s["name"] = "(no data)"
# Don't clobber a previously resolved name on a transient failure.
s["name"] = existing_names.get(s["structure_id"]) or "(no data)"
else:
structure_info = structure_info_obj.model_dump()
count += 1
Expand Down
44 changes: 44 additions & 0 deletions structures/tests/models/test_owners_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,50 @@ def test_update_will_not_break_on_403_error_from_structure_info(self):
structure = Structure.objects.get(id=structure_id)
self.assertEqual(structure.name, "(no data)")

@pook.on
def test_should_keep_last_known_name_when_universe_endpoint_fails(self):
# given
owner = OwnerFactory(user=self.user, structures_last_update_at=None)
structure_id = 1000000000001
solar_system = EveSolarSystemFactory()
structure_type = CitadelTypeFactory()
StructureFactory(
id=structure_id,
owner=owner,
eve_type=structure_type,
eve_solar_system=solar_system,
name="My Awesome Structure",
)
pook.get(
f"https://esi.evetech.net/corporations/{self.corporation_id}/structures",
reply=200,
response_json=[
{
"corporation_id": self.corporation_id,
"profile_id": 101853,
"reinforce_hour": 18,
"state": "shield_vulnerable",
"structure_id": structure_id,
"system_id": solar_system.id,
"type_id": structure_type.id,
},
],
)
pook.get(
f"https://esi.evetech.net/universe/structures/{structure_id}",
reply=500,
response_json={"error": "internal_error"},
)

# when
owner.update_structures_esi()

# then
owner.refresh_from_db()
self.assertFalse(owner.is_structure_sync_fresh)
structure = Structure.objects.get(id=structure_id)
self.assertEqual(structure.name, "My Awesome Structure")

@pook.on
def test_tags_are_not_modified_by_update(self):
# given
Expand Down
Loading