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

bundle analysis - add support for tokenless upload #741

Merged
merged 5 commits into from
Aug 12, 2024

Conversation

JerrySentry
Copy link
Contributor

@JerrySentry JerrySentry commented Aug 8, 2024

closes codecov/engineering-team#2206

Creates a subclass of TokenlessAuthentication to validate the BA upload endpoint, for tokenless upload to be successful will need the following in the request body (in addition to what is normally required):

  1. branch must be present with value of format forkname:main
  2. git_service must be present with value one of: github, gitlab, bitbucket, github_enterprise, gitlab_enterprise, bitbucket_server
  3. the repo is a public repo

With this the token head need not be provided.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-staging
Copy link

codecov-staging bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Aug 8, 2024

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2271 tests with 1 failed, 2264 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: services.tests.test_bundle_analysis
    Test name: test_load_report

    self = <sqlalchemy.engine.base.Connection object at 0x7f5df53e6570>
    dialect = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext'>>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    execution_options = immutabledict({'autocommit': symbol('PARSE_AUTOCOMMIT'), 'future_result': True})
    args = (<sqlalchemy.dialects.sqlite.base.SQLiteCompiler object at 0x7f5df53e4890>, [], <sqlalchemy.sql.elements.TextClause object at 0x7f5df52bbad0>, [])
    kw = {'cache_hit': symbol('CACHE_MISS')}
    branched = <sqlalchemy.engine.base.Connection object at 0x7f5df53e6570>
    yp = None
    conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f5df53e68a0>
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    fn = <function ConnectionEvents._listen.<locals>.wrap_before_cursor_execute at 0x7f5e01883ec0>
    evt_handled = False

    def _execute_context(
    self,
    dialect,
    constructor,
    statement,
    parameters,
    execution_options,
    *args,
    **kw
    ):
    """Create an :class:`.ExecutionContext` and execute, returning
    a :class:`_engine.CursorResult`."""

    branched = self
    if self.__branch_from:
    # if this is a "branched" connection, do everything in terms
    # of the "root" connection, *except* for .close(), which is
    # the only feature that branching provides
    self = self.__branch_from

    if execution_options:
    yp = execution_options.get("yield_per", None)
    if yp:
    execution_options = execution_options.union(
    {"stream_results": True, "max_row_buffer": yp}
    )

    try:
    conn = self._dbapi_connection
    if conn is None:
    conn = self._revalidate_connection()

    context = constructor(
    dialect, self, conn, execution_options, *args, **kw
    )
    except (exc.PendingRollbackError, exc.ResourceClosedError):
    raise
    except BaseException as e:
    self._handle_dbapi_exception(
    e, util.text_type(statement), parameters, None, None
    )

    if (
    self._transaction
    and not self._transaction.is_active
    or (
    self._nested_transaction
    and not self._nested_transaction.is_active
    )
    ):
    self._invalid_transaction()

    elif self._trans_context_manager:
    TransactionalContext._trans_ctx_check(self)

    if self._is_future and self._transaction is None:
    self._autobegin()

    context.pre_exec()

    if dialect.use_setinputsizes:
    context._set_input_sizes()

    cursor, statement, parameters = (
    context.cursor,
    context.statement,
    context.parameters,
    )

    if not context.executemany:
    parameters = parameters[0]

    if self._has_events or self.engine._has_events:
    for fn in self.dispatch.before_cursor_execute:
    statement, parameters = fn(
    self,
    cursor,
    statement,
    parameters,
    context,
    context.executemany,
    )

    if self._echo:

    self._log_info(statement)

    stats = context._get_cache_stats()

    if not self.engine.hide_parameters:
    self._log_info(
    "[%s] %r",
    stats,
    sql_util._repr_params(
    parameters, batches=10, ismulti=context.executemany
    ),
    )
    else:
    self._log_info(
    "[%s] [SQL parameters hidden due to hide_parameters=True]"
    % (stats,)
    )

    evt_handled = False
    try:
    if context.executemany:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_executemany:
    if fn(cursor, statement, parameters, context):
    evt_handled = True
    break
    if not evt_handled:
    self.dialect.do_executemany(
    cursor, statement, parameters, context
    )
    elif not parameters and context.no_parameters:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_execute_no_params:
    if fn(cursor, statement, context):
    evt_handled = True
    break
    if not evt_handled:
    self.dialect.do_execute_no_params(
    cursor, statement, context
    )
    else:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_execute:
    if fn(cursor, statement, parameters, context):
    evt_handled = True
    break
    if not evt_handled:
    > self.dialect.do_execute(
    cursor, statement, parameters, context
    )

    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1910:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>

    def do_execute(self, cursor, statement, parameters, context=None):
    > cursor.execute(statement, parameters)
    E sqlite3.OperationalError: no such column: asset_type

    .../local/lib/python3.12.../sqlalchemy/engine/default.py:736: OperationalError

    The above exception was the direct cause of the following exception:

    self = <shared.bundle_analysis.report.BundleAnalysisReport object at 0x7f5de4edbbf0>
    db_session = <sqlalchemy.orm.session.Session object at 0x7f5de4c20920>

    def _setup(self, db_session: DbSession):
    """
    Creates the schema for a new bundle report database.
    """
    try:
    schema_version = (
    db_session.query(Metadata)
    .filter_by(key=MetadataKey.SCHEMA_VERSION.value)
    .first()
    ).value
    if schema_version < SCHEMA_VERSION:
    log.info(
    f"Migrating Bundle Analysis DB schema from {schema_version} to {SCHEMA_VERSION}"
    )
    BundleAnalysisMigration(
    db_session, schema_version, SCHEMA_VERSION
    > ).migrate()

    .../local/lib/python3.12.../shared/bundle_analysis/report.py:212:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    .../local/lib/python3.12.../shared/bundle_analysis/db_migrations.py:43: in migrate
    self.migrations[version](self.db_session)
    .../local/lib/python3.12.../bundle_analysis/migrations/v003_modify_gzip_size_nullable.py:45: in modify_gzip_size_nullable
    db_session.execute(text(stmt))
    .../local/lib/python3.12.../sqlalchemy/orm/session.py:1717: in execute
    result = conn._execute_20(statement, params or {}, execution_options)
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1710: in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
    .../local/lib/python3.12.../sqlalchemy/sql/elements.py:334: in _execute_on_connection
    return connection._execute_clauseelement(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1577: in _execute_clauseelement
    ret = self._execute_context(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1953: in _execute_context
    self._handle_dbapi_exception(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:2134: in _handle_dbapi_exception
    util.raise_(
    .../local/lib/python3.12.../sqlalchemy/util/compat.py:211: in raise_
    raise exception
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1910: in _execute_context
    self.dialect.do_execute(
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>

    def do_execute(self, cursor, statement, parameters, context=None):
    > cursor.execute(statement, parameters)
    E sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: asset_type
    E [SQL:
    E INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)
    E SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type
    E FROM assets_old;
    E ]
    E (Background on this error at: https://sqlalche..../e/14/e3q8)

    .../local/lib/python3.12.../sqlalchemy/engine/default.py:736: OperationalError

    During handling of the above exception, another exception occurred:

    get_storage_service = <MagicMock name='get_appropriate_storage_service' id='140041249337184'>

    @pytest.mark.django_db
    @patch("services.bundle_analysis.get_appropriate_storage_service")
    def test_load_report(get_storage_service):
    storage = MemoryStorageService({})
    get_storage_service.return_value = storage

    repo = RepositoryFactory()
    commit = CommitFactory(repository=repo)

    # no commit report record
    assert load_report(commit) is None

    commit_report = CommitReportFactory(
    commit=commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
    )

    storage_path = StoragePaths.bundle_report.path(
    repo_key=ArchiveService.get_archive_hash(repo),
    report_key=commit_report.external_id,
    )

    # nothing in storage
    assert load_report(commit) is None

    with open("..../tests/samples/bundle_report.sqlite", "rb") as f:
    storage.write_file(get_bucket_name(), storage_path, f)

    > report = load_report(commit)

    services/tests/test_bundle_analysis.py:54:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    services/bundle_analysis.py:48: in load_report
    return loader.load(commit_report.external_id)
    .../local/lib/python3.12.../shared/bundle_analysis/storage.py:53: in load
    return BundleAnalysisReport(db_path)
    .../local/lib/python3.12.../shared/bundle_analysis/report.py:194: in __init__
    self._setup(db_session)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <shared.bundle_analysis.report.BundleAnalysisReport object at 0x7f5de4edbbf0>
    db_session = <sqlalchemy.orm.session.Session object at 0x7f5de4c20920>

    def _setup(self, db_session: DbSession):
    """
    Creates the schema for a new bundle report database.
    """
    try:
    schema_version = (
    db_session.query(Metadata)
    .filter_by(key=MetadataKey.SCHEMA_VERSION.value)
    .first()
    ).value
    if schema_version < SCHEMA_VERSION:
    log.info(
    f"Migrating Bundle Analysis DB schema from {schema_version} to {SCHEMA_VERSION}"
    )
    BundleAnalysisMigration(
    db_session, schema_version, SCHEMA_VERSION
    ).migrate()
    except OperationalError:
    # schema does not exist
    try:
    con = sqlite3.connect(self.db_path)
    > con.executescript(SCHEMA)
    E sqlite3.OperationalError: table bundles already exists

    .../local/lib/python3.12.../shared/bundle_analysis/report.py:217: OperationalError

1 similar comment
Copy link

codecov-public-qa bot commented Aug 8, 2024

Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time.

❌ Failed Test Results:

Completed 2271 tests with 1 failed, 2264 passed and 6 skipped.

View the full list of failed tests

pytest

  • Class name: services.tests.test_bundle_analysis
    Test name: test_load_report

    self = <sqlalchemy.engine.base.Connection object at 0x7f5df53e6570>
    dialect = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext'>>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    execution_options = immutabledict({'autocommit': symbol('PARSE_AUTOCOMMIT'), 'future_result': True})
    args = (<sqlalchemy.dialects.sqlite.base.SQLiteCompiler object at 0x7f5df53e4890>, [], <sqlalchemy.sql.elements.TextClause object at 0x7f5df52bbad0>, [])
    kw = {'cache_hit': symbol('CACHE_MISS')}
    branched = <sqlalchemy.engine.base.Connection object at 0x7f5df53e6570>
    yp = None
    conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f5df53e68a0>
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    fn = <function ConnectionEvents._listen.<locals>.wrap_before_cursor_execute at 0x7f5e01883ec0>
    evt_handled = False

    def _execute_context(
    self,
    dialect,
    constructor,
    statement,
    parameters,
    execution_options,
    *args,
    **kw
    ):
    """Create an :class:`.ExecutionContext` and execute, returning
    a :class:`_engine.CursorResult`."""

    branched = self
    if self.__branch_from:
    # if this is a "branched" connection, do everything in terms
    # of the "root" connection, *except* for .close(), which is
    # the only feature that branching provides
    self = self.__branch_from

    if execution_options:
    yp = execution_options.get("yield_per", None)
    if yp:
    execution_options = execution_options.union(
    {"stream_results": True, "max_row_buffer": yp}
    )

    try:
    conn = self._dbapi_connection
    if conn is None:
    conn = self._revalidate_connection()

    context = constructor(
    dialect, self, conn, execution_options, *args, **kw
    )
    except (exc.PendingRollbackError, exc.ResourceClosedError):
    raise
    except BaseException as e:
    self._handle_dbapi_exception(
    e, util.text_type(statement), parameters, None, None
    )

    if (
    self._transaction
    and not self._transaction.is_active
    or (
    self._nested_transaction
    and not self._nested_transaction.is_active
    )
    ):
    self._invalid_transaction()

    elif self._trans_context_manager:
    TransactionalContext._trans_ctx_check(self)

    if self._is_future and self._transaction is None:
    self._autobegin()

    context.pre_exec()

    if dialect.use_setinputsizes:
    context._set_input_sizes()

    cursor, statement, parameters = (
    context.cursor,
    context.statement,
    context.parameters,
    )

    if not context.executemany:
    parameters = parameters[0]

    if self._has_events or self.engine._has_events:
    for fn in self.dispatch.before_cursor_execute:
    statement, parameters = fn(
    self,
    cursor,
    statement,
    parameters,
    context,
    context.executemany,
    )

    if self._echo:

    self._log_info(statement)

    stats = context._get_cache_stats()

    if not self.engine.hide_parameters:
    self._log_info(
    "[%s] %r",
    stats,
    sql_util._repr_params(
    parameters, batches=10, ismulti=context.executemany
    ),
    )
    else:
    self._log_info(
    "[%s] [SQL parameters hidden due to hide_parameters=True]"
    % (stats,)
    )

    evt_handled = False
    try:
    if context.executemany:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_executemany:
    if fn(cursor, statement, parameters, context):
    evt_handled = True
    break
    if not evt_handled:
    self.dialect.do_executemany(
    cursor, statement, parameters, context
    )
    elif not parameters and context.no_parameters:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_execute_no_params:
    if fn(cursor, statement, context):
    evt_handled = True
    break
    if not evt_handled:
    self.dialect.do_execute_no_params(
    cursor, statement, context
    )
    else:
    if self.dialect._has_events:
    for fn in self.dialect.dispatch.do_execute:
    if fn(cursor, statement, parameters, context):
    evt_handled = True
    break
    if not evt_handled:
    > self.dialect.do_execute(
    cursor, statement, parameters, context
    )

    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1910:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>

    def do_execute(self, cursor, statement, parameters, context=None):
    > cursor.execute(statement, parameters)
    E sqlite3.OperationalError: no such column: asset_type

    .../local/lib/python3.12.../sqlalchemy/engine/default.py:736: OperationalError

    The above exception was the direct cause of the following exception:

    self = <shared.bundle_analysis.report.BundleAnalysisReport object at 0x7f5de4edbbf0>
    db_session = <sqlalchemy.orm.session.Session object at 0x7f5de4c20920>

    def _setup(self, db_session: DbSession):
    """
    Creates the schema for a new bundle report database.
    """
    try:
    schema_version = (
    db_session.query(Metadata)
    .filter_by(key=MetadataKey.SCHEMA_VERSION.value)
    .first()
    ).value
    if schema_version < SCHEMA_VERSION:
    log.info(
    f"Migrating Bundle Analysis DB schema from {schema_version} to {SCHEMA_VERSION}"
    )
    BundleAnalysisMigration(
    db_session, schema_version, SCHEMA_VERSION
    > ).migrate()

    .../local/lib/python3.12.../shared/bundle_analysis/report.py:212:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    .../local/lib/python3.12.../shared/bundle_analysis/db_migrations.py:43: in migrate
    self.migrations[version](self.db_session)
    .../local/lib/python3.12.../bundle_analysis/migrations/v003_modify_gzip_size_nullable.py:45: in modify_gzip_size_nullable
    db_session.execute(text(stmt))
    .../local/lib/python3.12.../sqlalchemy/orm/session.py:1717: in execute
    result = conn._execute_20(statement, params or {}, execution_options)
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1710: in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
    .../local/lib/python3.12.../sqlalchemy/sql/elements.py:334: in _execute_on_connection
    return connection._execute_clauseelement(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1577: in _execute_clauseelement
    ret = self._execute_context(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1953: in _execute_context
    self._handle_dbapi_exception(
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:2134: in _handle_dbapi_exception
    util.raise_(
    .../local/lib/python3.12.../sqlalchemy/util/compat.py:211: in raise_
    raise exception
    .../local/lib/python3.12.../sqlalchemy/engine/base.py:1910: in _execute_context
    self.dialect.do_execute(
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f5de4c20e60>
    cursor = <sqlite3.Cursor object at 0x7f5de44acac0>
    statement = '\n INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)\n SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type\n FROM assets_old;\n '
    parameters = ()
    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f5df53e59a0>

    def do_execute(self, cursor, statement, parameters, context=None):
    > cursor.execute(statement, parameters)
    E sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: asset_type
    E [SQL:
    E INSERT INTO assets (id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type)
    E SELECT id, session_id, name, normalized_name, size, gzip_size, uuid, asset_type
    E FROM assets_old;
    E ]
    E (Background on this error at: https://sqlalche..../e/14/e3q8)

    .../local/lib/python3.12.../sqlalchemy/engine/default.py:736: OperationalError

    During handling of the above exception, another exception occurred:

    get_storage_service = <MagicMock name='get_appropriate_storage_service' id='140041249337184'>

    @pytest.mark.django_db
    @patch("services.bundle_analysis.get_appropriate_storage_service")
    def test_load_report(get_storage_service):
    storage = MemoryStorageService({})
    get_storage_service.return_value = storage

    repo = RepositoryFactory()
    commit = CommitFactory(repository=repo)

    # no commit report record
    assert load_report(commit) is None

    commit_report = CommitReportFactory(
    commit=commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
    )

    storage_path = StoragePaths.bundle_report.path(
    repo_key=ArchiveService.get_archive_hash(repo),
    report_key=commit_report.external_id,
    )

    # nothing in storage
    assert load_report(commit) is None

    with open("..../tests/samples/bundle_report.sqlite", "rb") as f:
    storage.write_file(get_bucket_name(), storage_path, f)

    > report = load_report(commit)

    services/tests/test_bundle_analysis.py:54:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    services/bundle_analysis.py:48: in load_report
    return loader.load(commit_report.external_id)
    .../local/lib/python3.12.../shared/bundle_analysis/storage.py:53: in load
    return BundleAnalysisReport(db_path)
    .../local/lib/python3.12.../shared/bundle_analysis/report.py:194: in __init__
    self._setup(db_session)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    self = <shared.bundle_analysis.report.BundleAnalysisReport object at 0x7f5de4edbbf0>
    db_session = <sqlalchemy.orm.session.Session object at 0x7f5de4c20920>

    def _setup(self, db_session: DbSession):
    """
    Creates the schema for a new bundle report database.
    """
    try:
    schema_version = (
    db_session.query(Metadata)
    .filter_by(key=MetadataKey.SCHEMA_VERSION.value)
    .first()
    ).value
    if schema_version < SCHEMA_VERSION:
    log.info(
    f"Migrating Bundle Analysis DB schema from {schema_version} to {SCHEMA_VERSION}"
    )
    BundleAnalysisMigration(
    db_session, schema_version, SCHEMA_VERSION
    ).migrate()
    except OperationalError:
    # schema does not exist
    try:
    con = sqlite3.connect(self.db_path)
    > con.executescript(SCHEMA)
    E sqlite3.OperationalError: table bundles already exists

    .../local/lib/python3.12.../shared/bundle_analysis/report.py:217: OperationalError

Copy link

codecov bot commented Aug 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.05%. Comparing base (c0110f8) to head (6d9711e).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##               main       #741   +/-   ##
===========================================
  Coverage   96.05000   96.05000           
===========================================
  Files           814        814           
  Lines         18469      18489   +20     
===========================================
+ Hits          17740      17760   +20     
  Misses          729        729           
Flag Coverage Δ
unit 91.78% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.78% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JerrySentry JerrySentry marked this pull request as ready for review August 8, 2024 22:39
@JerrySentry JerrySentry requested a review from a team as a code owner August 8, 2024 22:39
Copy link
Contributor

@giovanni-guidini giovanni-guidini left a comment

Choose a reason for hiding this comment

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

LGTM

@JerrySentry JerrySentry added this pull request to the merge queue Aug 12, 2024
Merged via the queue into main with commit 1c2b6a8 Aug 12, 2024
17 of 18 checks passed
@JerrySentry JerrySentry deleted the aug_08_tokenless branch August 12, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tokenless][API] Add support for tokenless in auth classes
3 participants