Skip to content
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

Autonaming breaks for feeds with calendar_dates.txt #74

Open
mharvey opened this issue Aug 29, 2017 · 3 comments
Open

Autonaming breaks for feeds with calendar_dates.txt #74

mharvey opened this issue Aug 29, 2017 · 3 comments

Comments

@mharvey
Copy link
Contributor

mharvey commented Aug 29, 2017

When importing a feed with a calendar_dates.txt (The "TriMet Style") with the management command, the import fails with a nasty error when it tries to rename the feed at the very end. The rest of the import seems to work flawlessly.

When providing a name via the -n switch, the name generation is skipped and the error is avoided.

It appears that the Service objects are being created, but with Service.start_date and Service.end_date both nulled. When the importer gets to this part

try:
service = feed.service_set.order_by('id')[:1].get()
except Service.DoesNotExist:
service = None
if agency:
name = agency.name
if service:
name += service.start_date.strftime(' starting %Y-%m-%d')

the service exists, but service.start_date is None which causes the strftime to puke out this error:

INFO - Import completed in 2512.7 seconds.

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/mharvey/Envs/portal-rewrite/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Users/mharvey/Envs/portal-rewrite/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/mharvey/Envs/portal-rewrite/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/mharvey/Envs/portal-rewrite/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/mharvey/Envs/portal-rewrite/lib/python3.6/site-packages/multigtfs/management/commands/importgtfs.py", line 92, in handle
    name += service.start_date.strftime(' starting %Y-%m-%d')
AttributeError: 'NoneType' object has no attribute 'strftime'

I think the better behavior would be to check for an existing FeedInfo and use the start/end dates from that, then fall back to Service, and if the start_date is None or the Service doesn't exist, then finally fall back to the default name with the date on which the feed was imported.

@jwhitlock
Copy link
Member

I'd rather not make auto-naming any more complex than it already is, but that's probably the right thing for these horrible feeds. It may make sense to move this to a suggest_name function on the Feed model, so that we can get it under unit tests and code coverage, rather than import a whole feed to test it.

@mharvey
Copy link
Contributor Author

mharvey commented Aug 30, 2017

I like the idea of a suggest_name function. I'd be happy to take a stab at knocking this out over the next week or so if you want.

@jwhitlock
Copy link
Member

Thanks @mharvey I'd appreciate a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants