fix: use removeprefix and fix remaining underscore-prefix serialization paths#94
Open
ktrufanov-skycop wants to merge 1 commit intopunitarani:mainfrom
Open
fix: use removeprefix and fix remaining underscore-prefix serialization paths#94ktrufanov-skycop wants to merge 1 commit intopunitarani:mainfrom
ktrufanov-skycop wants to merge 1 commit intopunitarani:mainfrom
Conversation
punitarani
approved these changes
Mar 30, 2026
Owner
punitarani
left a comment
There was a problem hiding this comment.
lgtm just need to fix merge conflict
i can test locally and merge once fixed
…ization
paths
- Use removeprefix("_") instead of lstrip("_") for safer single-prefix
removal
- Fix date search serialization in dates.py (was still sending _3F to API)
- Fix round-trip selected_flight serialization in flights.py: pass enum
objects to serialize() instead of pre-resolving .name (which bypassed
the prefix-stripping logic)
- Add test for serialize_airline with numeric-prefix code
Contributor
Author
|
Superseded — rebased onto current main in a new PR. |
3 tasks
Contributor
Author
|
CI failure on Python 3.13 is a network timeout in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #90 (merged). Addresses the serialization gap flagged
by @punitarani in the review comment —
digit-prefixed airline codes like
_3Fwere still leaking into APIrequests and CLI output through paths not covered by the first PR.
Changes
removeprefix("_")inflights.pyanddates.pyserialize()functions — strip the synthetic underscore before sending codes to
Google Flights API
serialize_airline()incli/utils.py— same fix for CLI JSON outputselected_flightinflights.py— pass enum objects(
leg.airline,leg.departure_airport,leg.arrival_airport) toserialize()instead of pre-resolving.name, which bypassed theisinstancecheck and leaked_3Finto the request payloadserialize_airline()with numeric-prefix codeWhy
removeprefixoverlstriplstrip("_")would strip all leading underscores (__3F→3F).removeprefix("_")removes exactly one — matching the single underscoreadded by
generate_enums.pyfor digit-starting IATA codes.Test plan
serialize_airline(Airline._3F)returns{"code": "3F", "name": "FlyOne Armenia"}Greptile Summary
This follow-up PR closes the remaining serialization gaps from #90, ensuring digit-prefixed airline codes like
_3Fare stripped to their canonical IATA form (3F) across all code paths: Google Flights API requests (flights.py,dates.pyserialize functions), CLI JSON output (cli/utils.pyserialize_airline), and input parsing (core/parsers.pyparse_airlines). It also fixes a more subtle round-trip bug whereselected_flightlegs were passing.namestrings intoserialize(), bypassing theisinstance(obj, Airline)guard entirely.Key changes:
lstrip(\"_\")→removeprefix(\"_\")incli/utils.pyand bothserialize()functions — prevents over-stripping if a code somehow contained multiple leading underscoresdates.pyserialize()— was the missed path from fix: correct stale airline data for 3F and fix numeric-prefix airline filtering #90; now consistent withflights.pyflights.pyround-tripselected_flight— now passesleg.departure_airport,leg.arrival_airport, andleg.airlineenum objects (not.namestrings) so theisinstanceguard applies correctlyparsers.pyparse_airlines— correctly prefixes digit-leading codes with_before enum lookupdata/airlines.csvandAirline._3Fenum — updated from "Pacific Airways" to "FlyOne Armenia"One gap remains:
fli/cli/commands/dates.pyline 234 builds thequeryecho withairline.name(post-parse enum names), so\"_3F\"still leaks into thequery.airlinesfield of the JSON output for thedatescommand.Confidence Score: 4/5
Safe to merge with the minor caveat that the dates command's JSON query echo still leaks the underscore prefix for digit-prefixed airlines.
All API serialization paths and CLI result output are correctly fixed. The one remaining defect is in the informational query-echo field of the dates command JSON output (fli/cli/commands/dates.py:234), which was explicitly part of the PR's stated goal ("CLI output" leaks) but was missed. This is a real, user-visible inconsistency rather than a pure style issue, warranting a 4 rather than 5.
fli/cli/commands/dates.py — line 234 still uses airline.name without removeprefix("_") in the query echo dict.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD UserInput["User input: '3F'"] --> ParseAirlines["parse_airlines()\ncore/parsers.py\ncode[0].isdigit() → prepend '_'"] ParseAirlines --> EnumLookup["getattr(Airline, '_3F')\n→ Airline._3F"] EnumLookup --> TwoPaths{Output path} TwoPaths -->|API request| Serialize["serialize(obj)\nflights.py / dates.py\nobj.name.removeprefix('_')\n→ '3F' ✅"] TwoPaths -->|CLI JSON results| SerializeAirline["serialize_airline()\ncli/utils.py\nairline.name.removeprefix('_')\n→ '3F' ✅"] TwoPaths -->|CLI JSON query echo\ndates command| QueryEcho["airline.name\ncli/commands/dates.py:234\n→ '_3F' ❌ still leaks"] Serialize --> APIRequest["Google Flights API\nrequest payload"] SerializeAirline --> CLIOutput["CLI / MCP\nflight results"] QueryEcho --> QueryField["query.airlines field\nin JSON response"]Comments Outside Diff (1)
fli/cli/commands/dates.py, line 234 (link)This line serializes parsed
Airlineenum names directly into the JSONqueryfield. For digit-prefixed codes likeAirline._3F,airline.namereturns"_3F"rather than the user-supplied"3F". This is one of the serialization paths the PR description explicitly targets ("digit-prefixed airline codes … still leaking into … CLI output"), but it was missed here.The
flightscommand works correctly because it echoes the raw input strings before parsing. Thedatescommand echoes the post-parsedAirline.name, so the prefix leaks.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "fix: strip underscore prefix from digit-..." | Re-trigger Greptile
(4/5) You can add custom instructions or style guidelines for the agent here!