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

MultipleObjectsReturned at [...] get() returned more than one HitCount -- it returned 2! #91

Open
siovene opened this issue Mar 8, 2020 · 2 comments
Assignees
Labels

Comments

@siovene
Copy link

siovene commented Mar 8, 2020

I run hitcount 1.2.3 on Django 1.11.28

To register a hit, I use the following code, as per the docs:

<script src="{% static 'hitcount/jquery.postcsrf.js' %}"></script>

{% get_hit_count_js_variables for image as hitcount %}
<script type="text/javascript">
jQuery(document).ready(function($) {
    // use the template tags in our JavaScript call
    $.postCSRF("{{ hitcount.ajax_url }}", { hitcountPK : "{{ hitcount.pk }}" })
        .done(function(data) {
            var $el = $('.views .number');
            var views = parseInt($el.text());
            if (data.hit_counted) {
                $el.text(views + 1);
            }
        }).fail(function(data) {
            console.log('POST failed');
            console.log(data);
        });
});
</script>

However, every now and then, when I try to get the hit count on an object, I get the error in the title of this issue.

Sounds like there's a race condition and two HitCounts are created at the same time.

Are you aware of this? Is this an issue with django-hitcount or my code?

Thanks!

@bashu
Copy link
Collaborator

bashu commented Jul 4, 2020

Are you aware of this? Is this an issue with django-hitcount or my code?

how can I reproduce it?

@bashu bashu self-assigned this Jul 4, 2020
@bashu bashu added the bug label Jul 4, 2020
@siovene
Copy link
Author

siovene commented Jul 6, 2020

I'm sorry, @bashu, I do not have a minimal reproduction repository or anything. But I do use it as per the documentation. This is definitely an issue with concurrent hits happening at the same time, so there should be a locking mechanism in place to prevent this.

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

No branches or pull requests

2 participants