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

Revert "Sanitize comma separated fields" #153

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Changelog of threedi-schema
- Make model_settings.use_2d_rain and model_settings.friction_averaging booleans
- Remove columns referencing v2 in geometry_column
- Ensure correct use_* values when matching tables have no data
- Use custom types for comma separated and table text fields to strip extra white space
- Correct direction of dwf and surface map


Expand Down
42 changes: 1 addition & 41 deletions threedi_schema/domain/custom_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import geoalchemy2
from packaging import version
from sqlalchemy.types import Integer, Text, TypeDecorator, VARCHAR
from sqlalchemy.types import Integer, TypeDecorator, VARCHAR


class Geometry(geoalchemy2.types.Geometry):
Expand Down Expand Up @@ -66,46 +66,6 @@ class IntegerEnum(CustomEnum):
impl = Integer


class CSVText(TypeDecorator):
impl = Text
cache_ok = True

def process_bind_param(self, value, dialect):
if value is not None:
# custom clean up behavior
value = value.replace(" ", "").replace("\n", "")
return value

def process_result_value(self, value, dialect):
if value is not None:
# custom clean up behavior
value = value.replace(" ", "").replace("\n", "")
return value


class CSVTable(TypeDecorator):
impl = Text
cache_ok = True

def process_bind_param(self, value, dialect):
if value is not None:
# convert windows line endings to unix first
value = value.replace("\r\n", "\n")
# clean up each line
lines = value.split("\n")
cleaned_lines = [line.replace(" ", "") for line in lines if line]
value = "\n".join(cleaned_lines)
return value

def process_result_value(self, value, dialect):
if value is not None:
# no need to replace \r\n here as the value came from the DB
lines = value.split("\n")
cleaned_lines = [line.replace(" ", "") for line in lines if line]
value = "\n".join(cleaned_lines)
return value


class VarcharEnum(CustomEnum):
cache_ok = True
impl = VARCHAR
Loading
Loading