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

Fixing custom embedded documents regression #2051

Merged
merged 3 commits into from
Sep 2, 2022

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Sep 1, 2022

Fixes a regression introduced in v0.16.6 when working with custom embedded documents that would raise an error when a custom EmbeddedDocument class was used to populate a dynamic attribute of a Label field:

from datetime import datetime

import fiftyone as fo
import fiftyone.core.fields as fof
import fiftyone.core.odm as foo

class CameraInfo(foo.EmbeddedDocument):
    camera_id = fof.StringField(required=True)
    quality = fof.FloatField()
    description = fof.StringField()

class LabelMetadata(foo.DynamicEmbeddedDocument):
    created_at = fof.DateTimeField(default=datetime.utcnow)
    model_name = fof.StringField()

sample = fo.Sample(
    filepath="/path/to/image.png",
    camera_info=CameraInfo(
        camera_id="123456789",
        quality=99.0,
    ),
    weather=fo.Classification(
        label="sunny",
        confidence=0.95,
        metadata=LabelMetadata(
            model_name="resnet50",
            description="A dynamic field",
        )
    ),
)

dataset = fo.Dataset()

# Would raise an error on v0.16.6; now works
dataset.add_sample(sample)

@brimoor brimoor added the bug Bug fixes label Sep 1, 2022
@brimoor brimoor requested a review from a team September 1, 2022 18:17
@brimoor brimoor self-assigned this Sep 1, 2022
Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

LGTM

@brimoor brimoor merged commit 12f19e2 into develop Sep 2, 2022
@brimoor brimoor deleted the bugfix/custom-embedded-documents branch September 2, 2022 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants