Skip to content

Error while testing a command involving a database AND ray

When I test a command that needs a database and ray, test fails with :

UnboundExecutionError('Could not locate a bind configured on mapper mapped class ComputationResult->computation_result, SQL expression or this Session.')

With the "default" backend, test is OK.

Here is the code :

class TestDataReductionCmd(PostgresCommandTestCase):
    
    PLUGINS = ['outflow.management', 'tuto.data_reduction']

    def test_compute_more_ray(self, caplog):

        # --- setup configuration to use ray backend ---
        custom_config = {
            "backend": "ray",
            "ray": {"cluster_type": "local"}
        }
        config.update(custom_config)

        db_upgrade = ['management', 'db', 'upgrade', 'heads', '-ll', 'INFO']
        self.run_command(db_upgrade, force_dry_run = False)
        
        # --- create some fake data ---
        multiplier = randrange(10)

        # --- prepare command with its arguments ---
        command = [
            'compute_more_data',
            '--multiplier',
            f'{multiplier}',
            '-ll',
            'INFO'
        ]

        # --- run the command ---
        return_code, result = self.run_command(command, force_dry_run = False)

        # --- make assertions ---
        assert return_code == 0
        for i in range(40, 71, 10):
            res = [{'computation_result': i * multiplier}]
            assert res in result[0]['map_computation_result']

Sonny says he had already this error, and is due to the fact that models have bee cleared after the first run_command

Edited by florence-henry