Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid key-error when inserting asset chunks #550

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix tests, use .get()
  • Loading branch information
ajay-sentry committed Feb 28, 2025
commit bcbb45e68fc5e0a79a7c2fd4a6760597bf3f3a0d
8 changes: 2 additions & 6 deletions shared/bundle_analysis/parsers/v3.py
Original file line number Diff line number Diff line change
@@ -381,17 +381,12 @@ def _create_associations(self):
self.db_session.query(Asset)
.filter(
Asset.session_id == self.session.id,
# Asset.asset_type == AssetType.JAVASCRIPT,
)
.all()
)

print("IN HERE", assets)

asset_name_to_id = {asset.name: asset.id for asset in assets}

print("IN HERE 2", asset_name_to_id)

chunks: list[Chunk] = (
self.db_session.query(Chunk)
.filter(
@@ -416,8 +411,9 @@ def _create_associations(self):

inserts.extend(
[
dict(asset_id=asset_name_to_id[asset_name], chunk_id=chunk_id)
dict(asset_id=asset_name_to_id.get(asset_name), chunk_id=chunk_id)
for asset_name in asset_names
if asset_name_to_id.get(asset_name) is not None
]
)
if inserts:
25 changes: 18 additions & 7 deletions tests/unit/bundle_analysis/test_asset_association.py
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ def test_asset_association():
assert asset.uuid == curr_a_asset_mapping_after[hashed_name].uuid
for hashed_name, asset in curr_b_asset_mapping_before.items():
if asset.asset_type != AssetType.JAVASCRIPT:
assert asset.uuid != curr_b_asset_mapping_after[hashed_name].uuid
assert asset.uuid == curr_b_asset_mapping_after[hashed_name].uuid

# Same name -> asset associated
asset_a = prev_a_asset_mapping["asset-same-name-diff-modules.js"]
@@ -67,20 +67,31 @@ def test_asset_association():
asset_b = prev_b_asset_mapping["asset-same-name-diff-modules.js"]
assert (
curr_b_asset_mapping_after["asset-same-name-diff-modules.js"].uuid
== asset_b.uuid
!= asset_b.uuid
)

# Diff name, same modules -> asset associated
asset_a = prev_a_asset_mapping["asset-diff-name-same-modules-ONE.js"]
assert curr_a_asset_mapping_after["asset-diff-name-same-modules-TWO.js"]
assert (
asset_a.uuid
== curr_a_asset_mapping_after["asset-diff-name-same-modules-TWO.js"].uuid
)
asset_b = prev_b_asset_mapping["asset-diff-name-same-modules-ONE.js"]
assert curr_b_asset_mapping_after["asset-diff-name-same-modules-TWO.js"]

assert (
asset_b.uuid
== curr_b_asset_mapping_after["asset-diff-name-same-modules-TWO.js"].uuid
)
# Diff name, diff modules -> asset not associated
asset_a = prev_a_asset_mapping["asset-diff-name-diff-modules-ONE.js"]
assert curr_a_asset_mapping_after["asset-diff-name-diff-modules-TWO.js"]
assert (
asset_a.uuid
!= curr_a_asset_mapping_after["asset-diff-name-diff-modules-TWO.js"].uuid
)
asset_b = prev_b_asset_mapping["asset-diff-name-diff-modules-ONE.js"]
assert curr_b_asset_mapping_after["asset-diff-name-diff-modules-TWO.js"]
assert (
asset_b.uuid
!= curr_b_asset_mapping_after["asset-diff-name-diff-modules-TWO.js"].uuid
)

finally:
prev_bar.cleanup()
Loading
Oops, something went wrong.