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(auditlogs): only return necessary information in audit logs #83432

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

mdtro
Copy link
Member

@mdtro mdtro commented Jan 14, 2025

Be explicit about the keys returned in the data field of the AuditLogEntry model when serializing API responses.

@mdtro mdtro requested a review from wedamija January 14, 2025 20:26
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 14, 2025
@mdtro mdtro changed the title fix: only return necessary information in audit logs fix(auditlogs): only return necessary information in audit logs Jan 14, 2025
@mdtro mdtro requested a review from a team January 14, 2025 20:28
Copy link

codecov bot commented Jan 14, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
23502 1 23501 270
View the top 1 failed tests by shortest run time
tests.sentry.api.serializers.test_auditlogentry.AuditLogEntrySerializerTest::test_teams_conversion
Stack Traces | 1.23s run time
#x1B[1m#x1B[.../api/serializers/test_auditlogentry.py#x1B[0m:82: in test_teams_conversion
    log = AuditLogEntry.objects.create(
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/manager.py#x1B[0m:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/query.py#x1B[0m:679: in create
    obj.save(force_insert=True, using=self.db)
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[.../sentry/models/auditlogentry.py#x1B[0m:85: in save
    super().save(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/base.py#x1B[0m:892: in save
    self.save_base(
#x1B[1m#x1B[.../sentry/silo/base.py#x1B[0m:158: in override
    return original_method(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/base.py#x1B[0m:998: in save_base
    updated = self._save_table(
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/base.py#x1B[0m:1161: in _save_table
    results = self._do_insert(
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/base.py#x1B[0m:1202: in _do_insert
    return manager._insert(
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/manager.py#x1B[0m:87: in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
#x1B[1m#x1B[31m.venv/lib/python3.12.../db/models/query.py#x1B[0m:1847: in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
#x1B[1m#x1B[31m.venv/lib/python3.12.../models/sql/compiler.py#x1B[0m:1835: in execute_sql
    for sql, params in self.as_sql():
#x1B[1m#x1B[31m.venv/lib/python3.12.../models/sql/compiler.py#x1B[0m:1760: in as_sql
    self.prepare_value(field, self.pre_save_val(field, obj))
#x1B[1m#x1B[31m.venv/lib/python3.12.../models/sql/compiler.py#x1B[0m:1699: in prepare_value
    return field.get_db_prep_save(value, connection=self.connection)
#x1B[1m#x1B[31m.venv/lib/python3.12.../models/fields/__init__.py#x1B[0m:1008: in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
#x1B[1m#x1B[31m.venv/lib/python3.12.../models/fields/__init__.py#x1B[0m:1001: in get_db_prep_value
    value = self.get_prep_value(value)
#x1B[1m#x1B[.../models/fields/gzippeddict.py#x1B[0m:58: in get_prep_value
    return json.dumps(value)
#x1B[1m#x1B[.../sentry/utils/json.py#x1B[0m:112: in dumps
    return _default_encoder.encode(value)
#x1B[1m#x1B[31m.venv/lib/python3.12....../site-packages/simplejson/encoder.py#x1B[0m:296: in encode
    chunks = self.iterencode(o, _one_shot=True)
#x1B[1m#x1B[31m.venv/lib/python3.12....../site-packages/simplejson/encoder.py#x1B[0m:378: in iterencode
    return _iterencode(o, 0)
#x1B[1m#x1B[.../sentry/utils/json.py#x1B[0m:62: in better_default_encoder
    raise TypeError(repr(o) + " is not JSON serializable")
#x1B[1m#x1B[31mE   TypeError: <tests.sentry.api.serializers.test_auditlogentry.AuditLogEntrySerializerTest.test_teams_conversion.<locals>.MockTeam object at 0x7f2272f36a80> is not JSON serializable#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - mostly we rely on note to parse data safely, and we usually just use data to create various links on the FE. so restricting to just this safe data seems fine

@mdtro mdtro merged commit 2269fdb into master Jan 14, 2025
48 checks passed
@mdtro mdtro deleted the mdtro/auditlog-api-fix branch January 14, 2025 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants