Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where custom environment plugins were lost on dataset merge #1582

Merged

Conversation

williamcorsel
Copy link
Contributor

@williamcorsel williamcorsel commented Aug 12, 2024

Summary

I ran into an issue where plugins loaded into the Environment are not retained after merging. Turns out a generator is being passed to Environment.merge instead of the expected Sequence. This meant that custom plugins were never registered into the merged environment.

How to test

Reproducible example:

from datumaro.components.dataset import Dataset
from datumaro.components.environment import Environment
from datumaro.components.exporter import Exporter
from datumaro.components.hl_ops import HLOps
from datumaro.components.media import Image


class MyPlugin(Exporter):
    pass


environment = Environment()
environment.exporters.register('my_plugin', MyPlugin)

dataset1 = Dataset(media_type=Image, env=environment)
datasets = [dataset1, dataset1.clone()]
merged = HLOps.merge(*datasets)

assert 'my_plugin' in dataset1.env.exporters  # Passes
assert 'my_plugin' in merged.env.exporters  # Fails

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have added the description of my changes into CHANGELOG.​
  • I have updated the documentation accordingly

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Fixes crash where before the names of the plugins were passed instead
This fixes a bug where the default environment was always returned on merge
@williamcorsel williamcorsel marked this pull request as ready for review August 12, 2024 14:17
@williamcorsel williamcorsel requested review from a team as code owners August 12, 2024 14:17
@williamcorsel williamcorsel requested review from sooahleex and removed request for a team August 12, 2024 14:17
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.06%. Comparing base (10cd400) to head (45333f3).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1582      +/-   ##
===========================================
+ Coverage    81.04%   81.06%   +0.02%     
===========================================
  Files          278      278              
  Lines        32490    32490              
  Branches      6600     6599       -1     
===========================================
+ Hits         26330    26339       +9     
+ Misses        4706     4698       -8     
+ Partials      1454     1453       -1     
Flag Coverage Δ
ubuntu-20.04_Python-3.10 81.05% <100.00%> (+0.02%) ⬆️
windows-2022_Python-3.10 81.04% <100.00%> (+0.02%) ⬆️

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

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

Copy link
Contributor

@sooahleex sooahleex left a comment

Choose a reason for hiding this comment

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

Thank you for your interest to our project! Could you add an unit test for this?

src/datumaro/components/hl_ops/__init__.py Show resolved Hide resolved
Copy link
Contributor

@sooahleex sooahleex left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your interest into our projects.

@sooahleex sooahleex merged commit f93ae27 into openvinotoolkit:develop Aug 20, 2024
8 checks passed
@williamcorsel williamcorsel deleted the fix/environment-merge branch August 20, 2024 14:47
sooahleex added a commit to sooahleex/datumaro that referenced this pull request Aug 26, 2024
…penvinotoolkit#1582)

I ran into an issue where plugins loaded into the `Environment` are not
retained after merging. Turns out a generator is being passed to
[Environment.merge](https://github.com/openvinotoolkit/datumaro/blob/30b1add52d6fe458dba5e32e1f63ffeea999ad7b/src/datumaro/components/environment.py#L271)
instead of the expected Sequence. This meant that custom plugins were
never registered into the merged environment.

Reproducible example:
```python
from datumaro.components.dataset import Dataset
from datumaro.components.environment import Environment
from datumaro.components.exporter import Exporter
from datumaro.components.hl_ops import HLOps
from datumaro.components.media import Image


class MyPlugin(Exporter):
    pass


environment = Environment()
environment.exporters.register('my_plugin', MyPlugin)

dataset1 = Dataset(media_type=Image, env=environment)
datasets = [dataset1, dataset1.clone()]
merged = HLOps.merge(*datasets)

assert 'my_plugin' in dataset1.env.exporters  # Passes
assert 'my_plugin' in merged.env.exporters  # Fails

```
---------

Co-authored-by: Sooah Lee <[email protected]>
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.

2 participants