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

Fix bug that results in AttributeError - 'OccurrencePreview' object has no attribute 'object' #555

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

fatboystring
Copy link

Fixes issues #301 and #554

A couple of issues identified with the OccurrencePreview view - as follows:

  • The MRO of the OccurrencePreview class means that the ProcessFormView.get method is called first and foremost. ProcessFormView.get does not invoke the get_object method meaning the object is never fetched from the database.
  • The model attribute defined on the view class is Occurrence. The pk_url_kwarg attribute on the view class is occurrence_id. The url pattern that this view class is bound to does not define an occurrence_id pattern meaning the get_object method call would fail if the default implementation of get_object were used

As a result of the above, when get_context_data is called, the object attribute of the view has not been set, resulting in an AttributeError.

The fix involves:

  1. using the event_id from the url pattern to fetch the event from the db
  2. getting the associated occurrence by constructing the start/end dates from the url parameters and using the Period class to get occurrences for that point in time
  3. returning the occurrence if found
  4. raising an http 404 if the event could not be found, or no occurrences exist for the specified point in time

Thanks for the library. Please let me know if you'd like anything changed in the pull request

@coveralls
Copy link

coveralls commented Jul 6, 2023

Coverage Status

coverage: 80.36% (+0.4%) from 79.986% when pulling f6479c2 on fatboystring:bugfix/301 into 8aa6f87 on llazzaro:develop.

@llazzaro
Copy link
Owner

llazzaro commented Jul 6, 2023

@fatboystring
Copy link
Author

@llazzaro should be sorted now. Thanks

@h3x4git
Copy link

h3x4git commented Jul 17, 2023

I don't think this is compatible with #488

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

Successfully merging this pull request may close these issues.

4 participants