Skip to content

Commit

Permalink
fix: Move update to inside transaction block
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Aug 28, 2024
1 parent f8fb71e commit aa673c4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions posthog/warehouse/api/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,22 @@ def create(self, validated_data):
return view

def update(self, instance: Any, validated_data: Any) -> Any:
view: DataWarehouseSavedQuery = super().update(instance, validated_data)
with transaction.atomic():
view: DataWarehouseSavedQuery = super().update(instance, validated_data)

try:
view.columns = view.get_columns()
view.external_tables = view.s3_tables
except Exception as err:
raise serializers.ValidationError(str(err))
try:
view.columns = view.get_columns()
view.external_tables = view.s3_tables
except RecursionError:
raise serializers.ValidationError("Model contains a cycle")

except Exception as err:
raise serializers.ValidationError(str(err))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

with transaction.atomic():
view.save()

try:
DataWarehouseModelPath.objects.create_from_saved_query(view)
DataWarehouseModelPath.objects.update_from_saved_query(view)
except Exception:
logger.exception("Failed to update model path when updating view %s", view.name)

Expand Down

0 comments on commit aa673c4

Please sign in to comment.