Skip to content

[URGENT] Set JsonStringConverter to JSON deserializer option in WattTimeClient #623

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

Merged

Conversation

YaSuenag
Copy link
Member

@YaSuenag YaSuenag commented Apr 7, 2025

Pull Request

@vaughanknight @danuw Please review this PR. I think it is urgent bug.

Summary

co2_moer and co2_aoer have been supported since #611 , however WattTime client is possibility not to work after this change.

#611 introduces these values as enum, not `stiring. It might cause deserialization error.

fail: CarbonAware.WebApi.Filters.HttpResponseExceptionFilter[0]
      Exception: The JSON value could not be converted to CarbonAware.DataSources.WattTime.Constants.SignalTypes. Path: $.signal_type | LineNumber: 0 | BytePositionInLine: 102.
      System.Text.Json.JsonException: The JSON value could not be converted to CarbonAware.DataSources.WattTime.Constants.SignalTypes. Path: $.signal_type | LineNumber: 0 | BytePositionInLine: 102.
         at System.Text.Json.ThrowHelper.ThrowJsonException(String message)
         at System.Text.Json.Serialization.Converters.EnumConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
         at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
         at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
         at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
         at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
         at CarbonAware.DataSources.WattTime.Client.WattTimeClient.<>c__DisplayClass34_0.<<GetRegionFromCacheAsync>b__0>d.MoveNext() in /app/CarbonAware.DataSources/CarbonAware.DataSources.WattTime/src/Client/WattTimeClient.cs:line 315 

WattTime respond as following in this case. It was expected.

{
  "region": "CAISO",
  "region_full_name": "California Independent System Operator",
  "signal_type": "co2_aoer"
}

Changes

Checklist

  • Local Tests Passing?
  • CICD and Pipeline Tests Passing?
  • Added any new Tests?
  • Documentation Updates Made?
  • Are there any API Changes? If yes, please describe below.
  • This is not a breaking change. If it is, please describe it below.

Are there API Changes?

No

Is this a breaking change?

No

@YaSuenag YaSuenag requested a review from vaughanknight as a code owner April 7, 2025 05:37
Copy link
Collaborator

@danuw danuw 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

@danuw
Copy link
Collaborator

danuw commented Apr 8, 2025

Can we get at least one unit test that helps us spot if a change is likely to introduce this back please?

@vaughanknight vaughanknight requested a review from Copilot April 8, 2025 07:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Added test for enum serialization
@danuw danuw merged commit 88f0a9e into Green-Software-Foundation:dev Apr 8, 2025
9 checks passed
@YaSuenag YaSuenag deleted the pr/jsonstringconverter branch April 8, 2025 08:41
@danuw danuw added the v1.8 label Apr 15, 2025
@danuw danuw mentioned this pull request Apr 28, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants