django-rest-passwordreset
                                
                                 django-rest-passwordreset copied to clipboard
                                
                                    django-rest-passwordreset copied to clipboard
                            
                            
                            
                        IntegrityError at /api/password_reset/ null value in column "ip_address" violates not-null constraint
Hi, I have a problem with this dependency on production server. Locally works very good, but problem appears on server. It Django issue is?
django-rest-passwordreset version: 0.9.7 Django: 1.11.5
If you need any logs, let me know what you need.
Hi,
it might be possible that your request does not have "ip address" set. You are probably using a reverse proxy or load balancer or a unix socket?
Take a look at this PR and the comments, the HTTPXForwardedForMiddleware might help you: https://github.com/anx-ckreuzberger/django-rest-passwordreset/pull/7
This should be fixed by PR #40. It's not yet in a release, but it's in the master branch.
Should be fixed by release 1.1.0rc1, you can install it using
pip install "django-rest-passwordreset==1.1.0rc1"
@anx-ckreuzberger cant get it to work 😞
Can you provide an error message/exception/...?
pip install "django-rest-passwordreset==1.1.0rc1"
in my case it does not work, because the:
request.META.get('REMOTE_ADDR', getattr(settings, 'DJANGO_REST_PASSWORDRESET_REMOTE_ADDR', ''))
returns empty string, not null add a validation and it worked :(
solve it like this:
ip_address = request.META.get('REMOTE_ADDR', getattr(settings, 'DJANGO_REST_PASSWORDRESET_REMOTE_ADDR', ''))
user_agent = request.META.get('HTTP_USER_AGENT', getattr(settings, 'DJANGO_REST_PASSWORDRESET_HTTP_USER_AGENT', ''))
token = ResetPasswordToken.objects.create(
    user = user,
    user_agent = getattr(settings, 'DJANGO_REST_PASSWORDRESET_HTTP_USER_AGENT', '') if user_agent == '' else user_agent,
    ip_address = getattr(settings, 'DJANGO_REST_PASSWORDRESET_REMOTE_ADDR', '') if ip_address == '' else ip_address
)
@anx-ckreuzberger I've also bumped to the pre-release version 1.1.0rc1, but the IntegrityError still remains, even when I've set DJANGO_REST_PASSWORDRESET_HTTP_USER_AGENT and DJANGO_REST_PASSWORDRESET_REMOTE_ADDR in my settings configuration.
This is pretty weird because I've checked them about a hundred times but it still tries to set a null value for ip_address, which raises the error.
Any ideas? :)
look for the file in your local project venv/lib... modify the file in the line that I put
https://github.com/anx-ckreuzberger/django-rest-passwordreset/blob/85d30b7129605cf7651a79ebabb3dbac5e01e181/django_rest_passwordreset/views.py#L140
modify as I put in my previous comment
I know I'm the one that pressed the merge button on PR #40 , but I guess
                    # no token exists, generate a new token
                    token = ResetPasswordToken.objects.create(
                        user=user,
                        user_agent=request.META.get('HTTP_USER_AGENT',
                                                    getattr(settings, 'DJANGO_REST_PASSWORDRESET_HTTP_USER_AGENT', '')),
                        ip_address=request.META.get('REMOTE_ADDR',
                                                    getattr(settings, 'DJANGO_REST_PASSWORDRESET_REMOTE_ADDR', ''))
                    )
is just wrong?
I believe the implementation suggested by @vonorm here https://github.com/anx-ckreuzberger/django-rest-passwordreset/pull/40#issuecomment-506752772 is correct.
Any thoughts?
The idea is to work and not return error.
The problem that I had was that this request.META.get ('REMOTE_ADDR') returned empty text and therefore never set the default value assigned from the setting.
that say this: request.META.get ('REMOTE_ADDR', getattr (settings, 'DJANGO_REST_PASSWORDRESET_REMOTE_ADDR', '')) returned empty text, which does not allow it to be inserted into the database.
There are several alternatives, I suggested what worked for me PD: thanks
The bugfixes have been released on PyPi in version 1.1.0rc3.
You should be able install and test it using
pip install django-rest-passwordreset==1.1.0rc3
I am still getting the error: null value in column "ip_address" violates not-null constraint even after installing django-rest-passwordreset==1.1.0rc3 :(
Worked for me after migrating 👯♂
There is another error Data too long for column 'ip_address'.
This happens with the header
X-Forwarded-For | 2605:e000:100b:81b3:a5bb:913e:80c0:6e4, 172.68.47.143
DJANGO_REST_PASSWORDRESET_IP_ADDRESS_HEADER is set to use HTTP_X_FORWARDED_FOR.
Do I have to use HTTP_X_REAL_IP?