kopia lustrzana https://github.com/simonw/datasette
Group Issue #1910
Potential fix in datasette/views/database.py. Issue #1910 refers to columns having no type checking and upon analysis it sets columns with no types as a "text" string. Implemented a feature that checks if the instance variables within that column are either Integers or Floats and sets them accordingly. If they are not it is then set as a "text" string instead as originally intended. #1910 was not even an issue in the first place, I just classified Integers and Floats as themselves instead of everything being "text" strings.pull/2314/head
rodzic
35b2d267f7
commit
9200d59c08
|
@ -4,7 +4,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.8 (datasette) (2)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (datasette) (2)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -933,8 +933,22 @@ class TableCreateView(BaseView):
|
|||
return _error(["columns must be a list of objects"])
|
||||
if not column.get("name") or not isinstance(column.get("name"), str):
|
||||
return _error(["Column name is required"])
|
||||
# Check if type is specified
|
||||
|
||||
if not column.get("type"):
|
||||
column["type"] = "text"
|
||||
# If type is not specified, check the values in the column
|
||||
column_values = [value for value in column.get("values", []) if value is not None]
|
||||
|
||||
# Check if all values in the column are integers
|
||||
if all(isinstance(value, int) for value in column_values):
|
||||
column["type"] = "integer"
|
||||
# Check if all values in the column are floats
|
||||
elif all(isinstance(value, float) for value in column_values):
|
||||
column["type"] = "float"
|
||||
# If values are not all integers or floats, set type as "text"
|
||||
else:
|
||||
column["type"] = "text"
|
||||
|
||||
if column["type"] not in self._supported_column_types:
|
||||
return _error(
|
||||
["Unsupported column type: {}".format(column["type"])]
|
||||
|
|
Ładowanie…
Reference in New Issue