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

Remove system_date_time from device optional fields #78

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

waranlogesh
Copy link
Collaborator

@waranlogesh waranlogesh commented Aug 1, 2024

system_date_time is an embeds_one field. It should not be part for device's cast fields list. This cause error casting embeds with cast/4 for :system_date_time field is not supported, use cast_embed/3 instead

@waranlogesh waranlogesh self-assigned this Aug 1, 2024
@waranlogesh waranlogesh requested a review from hammeraj as a code owner August 1, 2024 13:55
@waranlogesh
Copy link
Collaborator Author

Before Fix

❯ mix test test/device_test.exs
Compiling 1 file (.ex)


  1) test to_struct/1 should parse given map to a valid device struct (Onvif.DeviceTest)
     test/device_test.exs:7
     ** (RuntimeError) casting embeds with cast/4 for :system_date_time field is not supported, use cast_embed/3 instead
     code: {:ok, device} = Onvif.Device.to_struct(device_map)
     stacktrace:
       (ecto 3.9.4) lib/ecto/changeset.ex:578: Ecto.Changeset.cast_type!/2
       (ecto 3.9.4) lib/ecto/changeset.ex:552: Ecto.Changeset.process_param/8
       (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
       (ecto 3.9.4) lib/ecto/changeset.ex:538: Ecto.Changeset.cast/6
       (onvif 0.3.4) lib/device.ex:88: Onvif.Device.changeset/2
       (onvif 0.3.4) lib/device.ex:65: Onvif.Device.to_struct/1
       test/device_test.exs:9: (test)



Finished in 0.02 seconds (0.02s async, 0.00s sync)
1 test, 1 failure

Randomized with seed 204547

After Fix

❯ mix test test/device_test.exs
Compiling 1 file (.ex)
.

Finished in 0.02 seconds (0.02s async, 0.00s sync)
1 test, 0 failures

Randomized with seed 62321

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved it to correct directory.

Copy link
Owner

@hammeraj hammeraj left a comment

Choose a reason for hiding this comment

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

Nice find

@hammeraj hammeraj merged commit d17dcb1 into main Aug 5, 2024
1 check passed
@hammeraj hammeraj deleted the lm/fix_device_to_struct branch August 5, 2024 16:01
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