whyceewhite / CarLess

Logging commuting trips completed using transit or pedestrian modes of transportation.
0 stars 0 forks source link

Random unsaved trips appearing in trip list #32

Closed whyceewhite closed 9 years ago

whyceewhite commented 9 years ago

Random, unsaved trips are showing up in the Trip list scene again a la #8.

This happened before because the context manager was pulling back pending trips. That was turned off but now they are appearing again. Some code was introduced where Settings or Vehicles (?) should bring back pending changes. Perhaps the pending is global and not for just one entity.

Or, is this happening because a Setting or Vehicle update automatically creates a new Trip because there is a relationship?? If so, make the relationship optional in the class (if it isn't already).

whyceewhite commented 9 years ago

This is occurring again, however, now I am certain why it is happening.

It turns out that just setting the managed object to nil does not make the managed object go away. In certain situations (Log Tracked Trip, for example), a Trip managed object is created to hold the trip's in progress values. When the trip is completed the user can save or discard the trip. The problem occurs when the user discards the trip. The managed object for that trip exists. Therefore, the next time the managed object context is saved then that trip will be saved. The fact that the variable pointing to it is nil'ed out doesn't have anything to do with the managed object.

As a result, if the user discards the trip, the code needs to send a deleteObject message to the trip and then save the context. That seems weird since the trip object was never saved to begin with. However, that is the way to flush it from being in a pending state.

To recreate:

  1. Go to Log Tracked trip. Pick a mode and start tracking. Stop tracking.
  2. The summary page will appear. Select the discard/trash option.
  3. Go to the Trips Listing page and there will be no evidence of that trip.
  4. Go to another action where you will save. For example, go back to the Manual trip and enter a trip. Save it.
  5. Go to the Trips Listing page and you will see the trip you just created as well as the trip that was discarded.
whyceewhite commented 9 years ago

Happening... again.

Press the save button on the manual entry without having a distance value (or a value of zero). This will cause the validation to fail but the Trip managed object will be created. Thus, when a save does occur, anywhere in the app, the random Trip will be saved.

This is happening because the trip managed object instance is created prior to validation. Thus, if validation fails, then the trip object exists, will be in the managed context as pending and will be saved whenever the context is saved.