Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit afa3bdb

Browse files
author
philippe VESSIERE
committed
Fix #130 - Fix coerce on IP Address Field.
- As defined in ban/auth/models.py, IPAddressField is not mandatory.
1 parent 3d31279 commit afa3bdb

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ban/auth/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Session(db.Model):
102102
"""
103103
user = db.ForeignKeyField(User, null=True)
104104
client = db.ForeignKeyField(Client, null=True)
105-
ip = db.IPAddressField(null=True) # TODO IPField
105+
ip = db.IPAddressField(null=True)
106106
email = db.CharField(null=True) # TODO EmailField
107107

108108
@property

ban/db/fields.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,13 @@ class IPAddressField(CharField):
206206
max_length = 100
207207

208208
def coerce(self, value=None):
209-
if value is None:
210-
value = '127.0.0.1'
211-
else:
209+
if value:
212210
value = str(value)
211+
try:
212+
ipaddress.ip_address(value)
213+
except ipaddress.AddressValueError:
214+
raise ValueError('Invalid IP Address "{}"'.format(value))
213215

214-
try:
215-
ipaddress.ip_address(value)
216-
except ipaddress.AddressValueError:
217-
raise ValueError('Invalid IP Address "{}"'.format(value))
218216
return value
219217

220218

0 commit comments

Comments
 (0)