Skip to content

Gracefully handle nullable fields in TransitAlert - #5349

Merged
leonardehrenfried merged 10 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:nullable-alert-fields
Sep 13, 2023
Merged

leonardehrenfried merged 10 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:nullable-alert-fields

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Sep 11, 2023 •

Copy link
Copy Markdown
Member

Summary

The return value of TransitAlert#descriptionText was producing NPE's in the GTFS GraphQL API so I made it and url return an explicit Optional so that call sites are forced to deal with this fact.

Since the API schema requires descriptionText to be non-null (which isn't the case for the GTFS-RT spec) I used some fallback logic so that it always returns a string.

If we don't want the fallback logic we will have to modify the schema. Let's discuss this at the dev meeting.

Unit tests

Test added.

@leonardehrenfried leonardehrenfried added the !Technical Debt Improve code quality, no functional changes. label Sep 11, 2023
@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner September 11, 2023 15:23
@codecov

codecov Bot commented Sep 11, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 56.52% and project coverage change: +0.07% 🎉

Comparison is base (7136d18) 66.37% compared to head (ceb1613) 66.44%.
Report is 24 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5349      +/-   ##
=============================================
+ Coverage      66.37%   66.44%   +0.07%     
- Complexity     15184    15211      +27     
=============================================
  Files           1787     1786       -1     
  Lines          69263    69236      -27     
  Branches        7339     7311      -28     
=============================================
+ Hits           45974    46005      +31     
+ Misses         20804    20751      -53     
+ Partials        2485     2480       -5     
Files Changed Coverage Δ
...a/org/opentripplanner/api/mapping/AlertMapper.java 28.57% <0.00%> (+5.04%) ⬆️
...lanner/routing/alertpatch/TransitAlertBuilder.java 69.62% <0.00%> (ø)
...modelapi/model/siri/sx/PtSituationElementType.java 59.75% <12.50%> (-0.49%) ⬇️
...ner/ext/gtfsgraphqlapi/datafetchers/AlertImpl.java 31.31% <100.00%> (+7.58%) ⬆️
...entripplanner/routing/alertpatch/TransitAlert.java 67.56% <100.00%> (ø)

... and 21 files with indirect coverage changes

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

jtorin
jtorin previously approved these changes Sep 12, 2023
optionsome
optionsome previously approved these changes Sep 12, 2023
Comment on lines +7 to +16
# these translations are a bit questionable, the above fields are already translated into the
# language selected in the request
alertDescriptionTextTranslations {
language
text
}
alertHeaderTextTranslations {
text
language
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should deprecate these at some point and add lang parameter to the fields

@leonardehrenfried

Copy link
Copy Markdown
Member Author

@optionsome @jtorin Sorry for the repeated reviews - I noticed that I returned null where I should have returned the empty list. I also made the test more realistic.

…sx/PtSituationElementType.java

Co-authored-by: Johan Torin <jtorin@users.noreply.github.com>
jtorin
jtorin previously approved these changes Sep 13, 2023
@t2gran t2gran added this to the 2.5 (next release) milestone Sep 13, 2023
@leonardehrenfried
leonardehrenfried merged commit 72fd373 into opentripplanner:dev-2.x Sep 13, 2023
t2gran pushed a commit that referenced this pull request Sep 13, 2023
@leonardehrenfried
leonardehrenfried deleted the nullable-alert-fields branch September 13, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Technical Debt Improve code quality, no functional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants