fix: convert "manual" service ids error into changeset error#1352
fix: convert "manual" service ids error into changeset error#1352
Conversation
90b539d to
42aced0
Compare
There was a problem hiding this comment.
contents:
: unzip -c test/support/fixtures/trainsformer/invalid,reasons=no-trips,no-stop-times,no-multi-route-trips.zip
Archive: test/support/fixtures/trainsformer/invalid,reasons=no-trips,no-stop-times,no-multi-route-trips.zip
extracting: multi_route_trips.txt
added_route_id,trip_id
inflating: stop_times.txt
trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_type,timepoint,bikes_allowed,nonstandard_track
inflating: trips.txt
route_id,service_id,trip_id,trip_headsign,trip_short_name,shape_id,direction_id,bikes_allowed,event_time| export = Trainsformer.get_export!(socket.assigns.export.id) | ||
|
|
||
| if imported_services == %{} do | ||
| {:noreply, assign(socket, error: "You must import at least one service")} |
There was a problem hiding this comment.
the reason for this PR is that I needed to get rid of this "error", because it's being used in a way that is both handled by Changeset's and doesn't match the way I want to return errors from the export validations, and conveniently, it actually makes it simpler to remove this code.
42aced0 to
b347095
Compare
| socket.assigns.uploaded_file_data, | ||
| socket.assigns.uploaded_file_name, | ||
| socket.assigns.disruption.id | ||
| ), |
There was a problem hiding this comment.
previously, if export_params["services"] was empty, this would actually crash and therefore we wouldn't upload the file to S3. So this does change the behavior. But, we now show the errors when validate runs, which does run after the Zip is uploaded (demonstrated in the test in this PR). I think this should be cleaned up and prevent errors, but we can also drop this commit for later.
I think the proper way to do this would be to add the zip contents as data on the changeset as a virtual field, and then use Ecto.Changeset.prepare_changes to upload to S3 before inserting into the DB, and update and validate the s3_path at that point. Then we never upload a file without the changeset being valid.
There was a problem hiding this comment.
Since github didn't show it very well, this is the code I'm talking about
with {:ok, s3_path} <-
ExportUpload.upload_to_s3(
socket.assigns.uploaded_file_data,
socket.assigns.uploaded_file_name,
socket.assigns.disruption.id
),There was a problem hiding this comment.
I think this should be cleaned up and prevent errors, but we can also drop this commit for later.
what is this here?
Personally I'm not super concerned about forcing every error into the changeset - it seems fine to me if we don't even create an export in the DB if the S3 upload fails.
There was a problem hiding this comment.
but in the case in which we uploaded an invalid file to S3, I agree that it should be cleaned up... I can make a follow-up ticket for that
There was a problem hiding this comment.
b347095 to
efd54a0
Compare
| "test/support/fixtures/trainsformer/invalid,reasons=no-trips,no-stop-times,no-multi-route-trips.zip" | ||
| ) | ||
| |> assert_text( | ||
| "Successfully imported export invalid,reasons=no-trips,no-stop-times,no-multi-route-trips.zip!" |
There was a problem hiding this comment.
note: I don't like the "successfully imported" but actually there's errors, but I think we can fix that later/follow up PR? thoughts?
There was a problem hiding this comment.
I'd prefer something like "Imported export with warnings" if possible. I personally think it would be fine to do that as part of this PR since it should be a relatively small change, but happy to put it off if it ends up being difficult.
|
@firestack could please you provide either acceptance criteria in the ticket or a description of the problem you're trying to solve in the PR? There might be some thread that I'm missing, but these are not immediately evident to me. |
|
@rudiejd Added the reasoning to the description |
Summary of changes
Asana Ticket: Show route and service ids missing errors
This PR is aiming to address a few factors
:errorsassign, so that I didn't have to compete with the error implementation in 🏹🚆 Trainsformer Validations: Make sure all errors are reported to frontend #1354 (see comment)update_exportfunction— #1352 (comment)
Before:

After:

Reviewer Checklist