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

test_compute_flow.py fails x 4, with "TypeError: string indices must be integers" #1360

Closed
trentmc opened this issue Mar 7, 2023 · 2 comments · Fixed by #1388
Closed

test_compute_flow.py fails x 4, with "TypeError: string indices must be integers" #1360

trentmc opened this issue Mar 7, 2023 · 2 comments · Fixed by #1388
Assignees
Labels
Priority: High Type: Bug Something isn't working

Comments

@trentmc
Copy link
Member

trentmc commented Mar 7, 2023

Bug report

I made a simple one-paragraph change to a README, in this PR.

Yet in remote CI, four tests failed. All sub-tests of test_compute_flow.py:

=========================== short test summary info ============================
FAILED tests/integration/ganache/test_compute_flow.py::test_compute_update_trusted_algorithm
FAILED tests/integration/ganache/test_compute_flow.py::test_compute_trusted_publisher
FAILED tests/integration/ganache/test_compute_flow.py::test_compute_just_provider_fees
FAILED tests/readmes/test_readmes.py::test_script_execution[script6] - TypeEr...

All four tests had the same failure:

>   return next(env for env in environments if float(env["priceMin"]) == float(0))
E   TypeError: string indices must be integers

Traceback

Full logs are here.

Here's one example traceback.

=================================== FAILURES ===================================
____________________ test_compute_update_trusted_algorithm _____________________

publisher_wallet = <LocalAccount '0x02354A1F160A3fd7ac8b02ee91F04104440B28E7'>
publisher_ocean = <ocean_lib.ocean.ocean.Ocean object at 0x7f9ae1bd2d30>
consumer_wallet = <LocalAccount '0x529043886F21D9bc1AE0feDb[75](https://github.com/oceanprotocol/ocean.py/actions/runs/4352325867/jobs/7604969865#step:9:76)1e34265a246e47'>
dataset_with_compute_service_generator = <ocean_lib.assets.ddo.DDO object at 0x7f9ae1cdc6a0>
algorithm = <ocean_lib.assets.ddo.DDO object at 0x7f9ae1bec880>
algorithm_with_different_publisher = <ocean_lib.assets.ddo.DDO object at 0x7f9ae2dc0280>

    @pytest.mark.integration
    def test_compute_update_trusted_algorithm(
        publisher_wallet,
        publisher_ocean,
        consumer_wallet,
        dataset_with_compute_service_generator,
        algorithm,
        algorithm_with_different_publisher,
    ):
        trusted_algo_list = [algorithm.generate_trusted_algorithms()]
        compute_service = get_first_service_by_type(
            dataset_with_compute_service_generator, "compute"
        )
    
        compute_service.update_compute_values(
            trusted_algorithms=trusted_algo_list,
            trusted_algo_publishers=[],
            allow_network_access=True,
            allow_raw_algorithm=False,
        )
    
        updated_dataset = publisher_ocean.assets.update(
            dataset_with_compute_service_generator, {"from": publisher_wallet}
        )
    
        # Expect to pass when trusted algorithm is used
>       run_compute_test(
            ocean_instance=publisher_ocean,
            publisher_wallet=publisher_wallet,
            consumer_wallet=consumer_wallet,
            dataset_and_userdata=AssetAndUserdata(updated_dataset, None),
            algorithm_and_userdata=AssetAndUserdata(algorithm, None),
            scenarios=["with_result"],
        )

tests/integration/ganache/test_compute_flow.py:510: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/integration/ganache/test_compute_flow.py:222: in run_compute_test
    free_c2d_env = ocean_instance.compute.get_free_c2d_environment(
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/enforce_typing/decorator.py:29: in wrapper
    return func(*args, **kwargs)
ocean_lib/ocean/ocean_compute.py:155: in get_free_c2d_environment
    return next(env for env in environments if float(env["priceMin"]) == float(0))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <dict_keyiterator object at 0x7f9ae1d7bd10>

>   return next(env for env in environments if float(env["priceMin"]) == float(0))
E   TypeError: string indices must be integers

ocean_lib/ocean/ocean_compute.py:155: TypeError
@Br1tBreaker
Copy link

bro
It looks like there is a type error occurring when trying to access a dictionary key as a string in the ocean_lib/ocean/ocean_compute.py module. Specifically, the get_free_c2d_environment function is attempting to access the "priceMin" key of a dictionary, but it is being treated as a string instead of an integer.

One possible solution is to convert the "priceMin" value to a float before accessing it as a dictionary key. Here's an example:

python

def get_free_c2d_environment(self) -> dict:
environments = self.compute_client.get_environments()
free_envs = [env for env in environments if float(env.get("priceMin", 0)) == 0.0]
if not free_envs:
raise Exception("No free environment found.")
return free_envs[0]

In this example, we use the get method of the dictionary to get the value of the "priceMin" key, with a default value of 0 if the key is not present. We then convert this value to a float before comparing it to 0.0.

Alternatively, you can modify the code that is passing in the dictionary to ensure that the "priceMin" key contains a float value instead of a string.

I hope this helps you to fix the issue with your code.

@trentmc
Copy link
Member Author

trentmc commented Mar 7, 2023

From @calina-c in slack:

There is a provider issue [version of this issue].
#606 in provider
"Known issue: compute environments disappear in CI"
Unfortunately it's our main blocker for now, and we can't work on provider nor ocean.py due to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants