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

add root_organization property to worker, clean up decoration service, change notification urls for GL #990

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nora-codecov
Copy link
Contributor

Decoration service was causing confusion for GitLab users. Cleaned it up and added some comments to clarify the current GL org strategy which is:

  • the root org owns the plan, so when dealing with a GL org's plan, look at the plan from the root org
  • membership and activation through plan_activated_user also happens on the root org instead of a subgroup org
  • if a notification has the plan or member url, give GL users the correct url (correct url is to root group, not subgroup)

more details on ticket codecov/engineering-team#2710

@nora-codecov nora-codecov requested a review from a team January 4, 2025 01:33
Copy link

github-actions bot commented Jan 4, 2025

This PR includes changes to shared. Please review them here: codecov/shared@2674ae9...3a445a9

.filter_by(service_id=service_id, service=self.service)
.one_or_none()
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not new - it's in shared, I'm just replicating it in worker.
I learned that in order to use shared's PlanService, which now calls .root_organization, sqlalchemy also needs to know about this property, so I had to add it.

@codecov-notifications
Copy link

codecov-notifications bot commented Jan 4, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1775 2 1773 1
View the top 2 failed tests by shortest run time
services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.05s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129ec90>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f46ad0>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61aa3b15d0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_commit_status_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c343a170>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b014be30>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129e810>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = CommitStatusNotificationContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = (
            CommitStatusNotificationContextBuilder().initialize_from_context(
                user_yaml, context
            )
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(
            name="fake_comparison", total_size_delta=1000, percentage_delta=1
        )
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_commit_status_context.py:292: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/commit_status.py:200: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/commit_status.py:175: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543100800'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError
services/bundle_analysis/notify/contexts/tests/test_comment_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.055s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129d490>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f47790>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61b0110bd0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_comment_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c32d1630>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b01489b0>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129f4d0>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = BundleAnalysisPRCommentContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = BundleAnalysisPRCommentContextBuilder().initialize_from_context(
            user_yaml, context
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(name="fake_comparison", percentage_delta=10.0)
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_comment_context.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/comment.py:208: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/comment.py:168: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543102480'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

Copy link

codecov bot commented Jan 4, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1775 2 1773 1
View the top 2 failed tests by shortest run time
services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.05s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129ec90>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f46ad0>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61aa3b15d0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_commit_status_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c343a170>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b014be30>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129e810>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = CommitStatusNotificationContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = (
            CommitStatusNotificationContextBuilder().initialize_from_context(
                user_yaml, context
            )
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(
            name="fake_comparison", total_size_delta=1000, percentage_delta=1
        )
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_commit_status_context.py:292: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/commit_status.py:200: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/commit_status.py:175: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543100800'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError
services/bundle_analysis/notify/contexts/tests/test_comment_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.055s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129d490>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f47790>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61b0110bd0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_comment_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c32d1630>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b01489b0>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129f4d0>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = BundleAnalysisPRCommentContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = BundleAnalysisPRCommentContextBuilder().initialize_from_context(
            user_yaml, context
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(name="fake_comparison", percentage_delta=10.0)
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_comment_context.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/comment.py:208: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/comment.py:168: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543102480'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

Copy link

github-actions bot commented Jan 4, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1776 2 1773 1
View the top 2 failed tests by shortest run time
test_initialize_from_context
Stack Traces | 0.050s run time
self = &lt;sqlalchemy.engine.base.Connection object at 0x7f61b129ec90&gt;
dialect = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
constructor = &lt;bound method DefaultExecutionContext._init_compiled of &lt;class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'&gt;&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'&gt;}
args = (&lt;sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f46ad0&gt;, [immutabledict({})])
conn = &lt;sqlalchemy.pool.base._ConnectionFairy object at 0x7f61aa3b15d0&gt;
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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:
&gt;                   self.dialect.do_execute(
                        cursor, statement, parameters, context
                    )

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
cursor = &lt;cursor object at 0x7f61b03ac5e0; closed: -1&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'&gt;}
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def do_execute(self, cursor, statement, parameters, context=None):
&gt;       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py:608: ProgrammingError

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

self = &lt;worker.services.bundle_analysis.notify.contexts.tests.test_commit_status_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c343a170&gt;
dbsession = &lt;sqlalchemy.orm.session.Session object at 0x7f61b014be30&gt;
mocker = &lt;pytest_mock.plugin.MockFixture object at 0x7f61b129e810&gt;

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = CommitStatusNotificationContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = (
            CommitStatusNotificationContextBuilder().initialize_from_context(
                user_yaml, context
            )
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(
            name="fake_comparison", total_size_delta=1000, percentage_delta=1
        )
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
&gt;       other_context = other_builder.build_context().get_result()

services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py:292: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
services/bundle_analysis/notify/contexts/commit_status.py:200: in build_context
    .evaluate_should_use_upgrade_message()
/usr/local/lib/python3.13/site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
services/bundle_analysis/notify/contexts/commit_status.py:175: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
/usr/local/lib/python3.13/site-packages/sqlalchemy/util/compat.py:182: in raise_
    raise exception
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
cursor = &lt;cursor object at 0x7f61b03ac5e0; closed: -1&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'&gt;}
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def do_execute(self, cursor, statement, parameters, context=None):
&gt;       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543100800'&gt;, 'try_to_auto_activate_3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'&gt;, 'param_1': 1}]
E       (Background on this error at: http://sqlalche.me/e/13/f405)

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py:608: ProgrammingError
test_initialize_from_context
Stack Traces | 0.055s run time
self = &lt;sqlalchemy.engine.base.Connection object at 0x7f61b129d490&gt;
dialect = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
constructor = &lt;bound method DefaultExecutionContext._init_compiled of &lt;class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'&gt;&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'&gt;}
args = (&lt;sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f47790&gt;, [immutabledict({})])
conn = &lt;sqlalchemy.pool.base._ConnectionFairy object at 0x7f61b0110bd0&gt;
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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:
&gt;                   self.dialect.do_execute(
                        cursor, statement, parameters, context
                    )

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
cursor = &lt;cursor object at 0x7f61b01484f0; closed: -1&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'&gt;}
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def do_execute(self, cursor, statement, parameters, context=None):
&gt;       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py:608: ProgrammingError

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

self = &lt;worker.services.bundle_analysis.notify.contexts.tests.test_comment_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c32d1630&gt;
dbsession = &lt;sqlalchemy.orm.session.Session object at 0x7f61b01489b0&gt;
mocker = &lt;pytest_mock.plugin.MockFixture object at 0x7f61b129f4d0&gt;

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = BundleAnalysisPRCommentContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = BundleAnalysisPRCommentContextBuilder().initialize_from_context(
            user_yaml, context
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(name="fake_comparison", percentage_delta=10.0)
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
&gt;       other_context = other_builder.build_context().get_result()

services/bundle_analysis/notify/contexts/tests/test_comment_context.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
services/bundle_analysis/notify/contexts/comment.py:208: in build_context
    .evaluate_should_use_upgrade_message()
/usr/local/lib/python3.13/site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
services/bundle_analysis/notify/contexts/comment.py:168: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
/usr/local/lib/python3.13/site-packages/sqlalchemy/util/compat.py:182: in raise_
    raise exception
/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0&gt;
cursor = &lt;cursor object at 0x7f61b01484f0; closed: -1&gt;
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'&gt;}
context = &lt;sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50&gt;

    def do_execute(self, cursor, statement, parameters, context=None):
&gt;       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': &lt;MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543102480'&gt;, 'try_to_auto_activate_3': &lt;MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'&gt;, 'param_1': 1}]
E       (Background on this error at: http://sqlalche.me/e/13/f405)

/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py:608: ProgrammingError

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

root = None
if self.service == "gitlab" and self.parent_service_id:
root = self
while root.parent_service_id is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think (but could be wrong) if self._get_owner_by_service can return None (from the .one_or_none() it seems possible, there are no typehints in the functions) then you will have a NoneType has no property "parent_service_id" error.

It would be good to add explicit typehints to the functions too

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, could we ever infinite loop because the parent_service_id is always None? Would we like to cap it after 10 iterations or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added typehints, and changed that query to .one() @giovanni-guidini

@adrian-codecov if parent_service_id is None the while breaks - I think you mean the opposite, it will infinite loop if it's never None. This condition would only happen if our data was bad and there was a set of Owners referencing back and forth at each other. We don't have anything to prevent this, but it really should never happen. We have GL webhooks that should keep this field updated with the state on GL. I think the risk is low :)

@@ -31,8 +29,8 @@ class DecorationDetails(object):
decoration_type: Decoration
reason: str
should_attempt_author_auto_activation: bool = False
activation_org_ownerid: int = None
activation_author_ownerid: int = None
activation_org_ownerid: int | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 ty

func.public.get_gitlab_root_group(org.ownerid)
).first()
# do not access plan directly - only through PlanService
org_plan = PlanService(current_org=org)
Copy link
Contributor

Choose a reason for hiding this comment

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

The PlanService doesn't seem to go looking for the root org (looking at main)

I think I'm missing a code change... does this PR depend on an unmerged change to shared too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, codecov/shared#461 ok ok

@@ -50,7 +48,7 @@ def determine_uploads_used(plan_service: PlanService) -> int:

def determine_decoration_details(
enriched_pull: EnrichedPull, empty_upload=None
) -> dict:
) -> DecorationDetails:
Copy link
Contributor

Choose a reason for hiding this comment

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

🏆

@@ -57,6 +58,16 @@ def get_dashboard_base_url() -> str:
return configured_dashboard_url or "https://app.codecov.io"


def _get_username_for_url(repository: Repository) -> str:
username = repository.owner.username
if repository.owner.service == Service.GITLAB.value:
Copy link
Contributor

Choose a reason for hiding this comment

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

Idk if we save service always as "gitlab" vs "GitLab" or something like that, might be worth lowercasing this just in case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it follows the enum values in Service, just checked metabase, it will only be gitlab

Copy link

github-actions bot commented Jan 8, 2025

This PR includes changes to shared. Please review them here: codecov/shared@609e56d...990c398

@codecov-qa
Copy link

codecov-qa bot commented Jan 8, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1775 2 1773 1
View the top 2 failed tests by shortest run time
services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.05s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129ec90>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f46ad0>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61aa3b15d0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_commit_status_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c343a170>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b014be30>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129e810>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = CommitStatusNotificationContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = (
            CommitStatusNotificationContextBuilder().initialize_from_context(
                user_yaml, context
            )
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(
            name="fake_comparison", total_size_delta=1000, percentage_delta=1
        )
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_commit_status_context.py:292: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/commit_status.py:200: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/commit_status.py:175: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543100800'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError
services/bundle_analysis/notify/contexts/tests/test_comment_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.055s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129d490>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f47790>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61b0110bd0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_comment_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c32d1630>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b01489b0>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129f4d0>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = BundleAnalysisPRCommentContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = BundleAnalysisPRCommentContextBuilder().initialize_from_context(
            user_yaml, context
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(name="fake_comparison", percentage_delta=10.0)
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_comment_context.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/comment.py:208: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/comment.py:168: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543102480'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

Copy link

codecov-public-qa bot commented Jan 8, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1775 2 1773 1
View the top 2 failed tests by shortest run time
services/bundle_analysis/notify/contexts/tests/test_commit_status_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.05s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129ec90>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f46ad0>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61aa3b15d0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_commit_status_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c343a170>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b014be30>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129e810>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = CommitStatusNotificationContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = (
            CommitStatusNotificationContextBuilder().initialize_from_context(
                user_yaml, context
            )
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(
            name="fake_comparison", total_size_delta=1000, percentage_delta=1
        )
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_commit_status_context.py:292: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/commit_status.py:200: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/commit_status.py:175: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b03ac5e0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543100800'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543102480'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError
services/bundle_analysis/notify/contexts/tests/test_comment_context.py::TestBundleAnalysisPRCommentNotificationContext::test_initialize_from_context
Stack Traces | 0.055s run time
self = <sqlalchemy.engine.base.Connection object at 0x7f61b129d490>
dialect = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
constructor = <bound method DefaultExecutionContext._init_compiled of <class 'sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2'>>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
args = (<sqlalchemy.dialects.postgresql.psycopg2.PGCompiler_psycopg2 object at 0x7f61b0f47790>, [immutabledict({})])
conn = <sqlalchemy.pool.base._ConnectionFairy object at 0x7f61b0110bd0>
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def _execute_context(
        self, dialect, constructor, statement, parameters, *args
    ):
        """Create an :class:`.ExecutionContext` and execute, returning
        a :class:`_engine.ResultProxy`.
    
        """
    
        try:
            try:
                conn = self.__connection
            except AttributeError:
                # escape "except AttributeError" before revalidating
                # to prevent misleading stacktraces in Py3K
                conn = None
            if conn is None:
                conn = self._revalidate_connection()
    
            context = constructor(dialect, self, conn, *args)
        except BaseException as e:
            self._handle_dbapi_exception(
                e, util.text_type(statement), parameters, None, None
            )
    
        if context.compiled:
            context.pre_exec()
    
        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.engine.logger.info(statement)
            if not self.engine.hide_parameters:
                self.engine.logger.info(
                    "%r",
                    sql_util._repr_params(
                        parameters, batches=10, ismulti=context.executemany
                    ),
                )
            else:
                self.engine.logger.info(
                    "[SQL parameters hidden due to hide_parameters=True]"
                )
    
        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.13.../sqlalchemy/engine/base.py:1276: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       psycopg2.ProgrammingError: can't adapt type 'MagicMock'

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

self = <worker.services.bundle_analysis.notify.contexts.tests.test_comment_context.TestBundleAnalysisPRCommentNotificationContext object at 0x7f61c32d1630>
dbsession = <sqlalchemy.orm.session.Session object at 0x7f61b01489b0>
mocker = <pytest_mock.plugin.MockFixture object at 0x7f61b129f4d0>

    def test_initialize_from_context(self, dbsession, mocker):
        head_commit, _ = get_commit_pair(dbsession)
        user_yaml = UserYaml.from_dict(PATCH_CENTRIC_DEFAULT_CONFIG)
        builder = BundleAnalysisPRCommentContextBuilder().initialize(
            head_commit, user_yaml, GITHUB_APP_INSTALLATION_DEFAULT_NAME
        )
        context = builder.get_result()
        context.commit_report = MagicMock(name="fake_commit_report")
        context.bundle_analysis_report = MagicMock(name="fake_bundle_analysis_report")
        context.pull = MagicMock(name="fake_pull")
    
        other_builder = BundleAnalysisPRCommentContextBuilder().initialize_from_context(
            user_yaml, context
        )
        other_context = other_builder.get_result()
    
        assert context.commit == other_context.commit
        assert context.commit_report == other_context.commit_report
        assert context.bundle_analysis_report == other_context.bundle_analysis_report
        assert context.pull == other_context.pull
        with pytest.raises(ContextNotLoadedError):
            other_context.bundle_analysis_comparison
    
        fake_comparison = MagicMock(name="fake_comparison", percentage_delta=10.0)
        mocker.patch.object(
            ComparisonLoader, "get_comparison", return_value=fake_comparison
        )
>       other_context = other_builder.build_context().get_result()

.../contexts/tests/test_comment_context.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../notify/contexts/comment.py:208: in build_context
    .evaluate_should_use_upgrade_message()
.../local/lib/python3.13.../site-packages/sentry_sdk/tracing_utils.py:673: in func_with_tracing
    return func(*args, **kwargs)
.../notify/contexts/comment.py:168: in evaluate_should_use_upgrade_message
    successful_activation = activate_user(
services/activation.py:94: in activate_user
    ).first()
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3429: in first
    ret = list(self[0:1])
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3203: in __getitem__
    return list(res)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3535: in __iter__
    return self._execute_and_instances(context)
.../local/lib/python3.13.../sqlalchemy/orm/query.py:3560: in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1011: in execute
    return meth(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/sql/elements.py:298: in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1124: in _execute_clauseelement
    ret = self._execute_context(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1316: in _execute_context
    self._handle_dbapi_exception(
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1510: in _handle_dbapi_exception
    util.raise_(
.../local/lib/python3.13.../sqlalchemy/util/compat.py:182: in raise_
    raise exception
.../local/lib/python3.13.../sqlalchemy/engine/base.py:1276: in _execute_context
    self.dialect.do_execute(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <sqlalchemy.dialects.postgresql.psycopg2.PGDialect_psycopg2 object at 0x7f61b19e96d0>
cursor = <cursor object at 0x7f61b01484f0; closed: -1>
statement = 'SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 \n LIMIT %(param_1)s'
parameters = {'param_1': 1, 'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057..._3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>}
context = <sqlalchemy.dialects.postgresql.psycopg2.PGExecutionContext_psycopg2 object at 0x7f61b028da50>

    def do_execute(self, cursor, statement, parameters, context=None):
>       cursor.execute(statement, parameters)
E       sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'MagicMock'
E       [SQL: SELECT public.try_to_auto_activate(%(try_to_auto_activate_2)s, %(try_to_auto_activate_3)s) AS try_to_auto_activate_1 
E        LIMIT %(param_1)s]
E       [parameters: {'try_to_auto_activate_2': <MagicMock name='fake_pull.database_pull.repository.owner.ownerid' id='140057543102480'>, 'try_to_auto_activate_3': <MagicMock name='fake_pull.database_pull.get_db_session().query().filter().first().ownerid' id='140057543099792'>, 'param_1': 1}]
E       (Background on this error at: http://sqlalche..../e/13/f405)

.../local/lib/python3.13.../sqlalchemy/engine/default.py:608: ProgrammingError

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

@adrian-codecov
Copy link
Contributor

Lgtm, waiting on the Shared update and can approve then 👌

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.

3 participants