palkan / logidze

Database changes log for Rails
MIT License
1.59k stars 74 forks source link

Return nil when getting a version and there's no log_data #235

Closed kpg-ideon closed 1 year ago

kpg-ideon commented 1 year ago

What is the purpose of this pull request?

Suggest a behavior change to the model's #at and #at_version methods (non-exclamation-mark versions).

What changes did you make? (overview)

When using #at(version: v) or #at_version(v) to attempt to get a specific version of a model instance, but log_data hasn't been set yet, return nil instead of the current behavior.

The current behavior is to raise NoMethodError ("undefined method 'version' for nil:NilClass"). For the non-exclamation-point versions of these methods, I believe it is less surprising to instead get nil.

Is there anything you'd like reviewers to focus on?

Please let me know if you like this idea, but would like some changes to this PR (such as actually mentioning this edge-case in the README.md).

Checklist

palkan commented 1 year ago

Thanks! Returning nil totally makes sense.