django-auditlog icon indicating copy to clipboard operation
django-auditlog copied to clipboard

Django DataError with the remote_addr field when attempting to save it in Postgresql

Open rrguedes opened this issue 2 years ago • 0 comments

Hello,

I'm facing a strange error when saving an admin model in Postgresql. After some research, I realized it has something to do with the auditlog. The exception is being generated because Django does not recognize the GenericIPAddressField (inet) type as correct. I've checked and my server is sending both X-Forwarded-For and REMOTE-ADDR METAs to the API, but as in auditlog/middleware.py X-Forwarded-For field is got if not empty. The error doesn't happen at my local machine, nor to me once I deploy it for an Azure App Service. But strangely it happens for the clients using it.

I'm using the automatic log approach and all I did was install auditlog and register my Models.

image

I believe the problem is being caused by the fact that the current value ends with ":" and the split operation in auditlog/middleware.py considers a comma "," for splitting purposes. The way I see it, and I might be wrong, is to include an alternative split method considering ":" for cases when we do have ports in X-Forwarded-For value. Does it make sense?

image

Thanks.

rrguedes avatar Aug 12 '22 21:08 rrguedes