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

IntegrityError at /api/password_reset/ null value in column "ip_address" violates not-null constraint #34

Closed
TorfinS opened this issue Apr 4, 2019 · 15 comments

Comments

@TorfinS
Copy link

TorfinS commented Apr 4, 2019

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

@TorfinS
Copy link
Author

TorfinS commented Apr 4, 2019

If you need any logs, let me know what you need.

@anx-ckreuzberger
Copy link
Contributor

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: #7

@anx-ckreuzberger
Copy link
Contributor

This should be fixed by PR #40. It's not yet in a release, but it's in the master branch.

@anx-ckreuzberger
Copy link
Contributor

Should be fixed by release 1.1.0rc1, you can install it using

pip install "django-rest-passwordreset==1.1.0rc1"

@joaquinperaza
Copy link

@anx-ckreuzberger cant get it to work 😞

@anx-ckreuzberger
Copy link
Contributor

Can you provide an error message/exception/...?

@idkc-aios
Copy link

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
)

@wencakisa
Copy link
Contributor

@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? :)

@idkc-aios
Copy link

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

@anx-ckreuzberger
Copy link
Contributor

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 #40 (comment) is correct.

Any thoughts?

@idkc-aios
Copy link

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

@anx-ckreuzberger
Copy link
Contributor

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

@shiveshsky
Copy link

shiveshsky commented Aug 20, 2019

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 👯‍♂

@ghost ghost self-assigned this Feb 7, 2020
@discover59
Copy link

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?

@nezhar
Copy link
Member

nezhar commented Sep 10, 2024

Fixed since 1.4.0

@nezhar nezhar closed this as completed Sep 10, 2024
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

8 participants