{"action":"created","issue":{"url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/359","repository_url":"https://api.github.com/repos/mkleehammer/pyodbc","labels_url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/359/labels{/name}","comments_url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/359/comments","events_url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/359/events","html_url":"https://github.com/mkleehammer/pyodbc/issues/359","id":303560128,"number":359,"title":"Django, invalid precision value when inserting more than 4000 characters into TextField","user":{"login":"titomisa","id":25230980,"avatar_url":"https://avatars3.githubusercontent.com/u/25230980?v=4","gravatar_id":"","url":"https://api.github.com/users/titomisa","html_url":"https://github.com/titomisa","followers_url":"https://api.github.com/users/titomisa/followers","following_url":"https://api.github.com/users/titomisa/following{/other_user}","gists_url":"https://api.github.com/users/titomisa/gists{/gist_id}","starred_url":"https://api.github.com/users/titomisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titomisa/subscriptions","organizations_url":"https://api.github.com/users/titomisa/orgs","repos_url":"https://api.github.com/users/titomisa/repos","events_url":"https://api.github.com/users/titomisa/events{/privacy}","received_events_url":"https://api.github.com/users/titomisa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-08T17:14:54Z","updated_at":"2018-03-08T18:08:47Z","closed_at":null,"author_association":"NONE","body":"Please first make sure you have looked at:\r\n\r\n* Documentation: https://github.com/mkleehammer/pyodbc/wiki\r\n* Other issues\r\n\r\n### Environment\r\n\r\nTo diagnose, we usually need to know the following, including version numbers.  On Windows, be\r\nsure to specify 32-bit Python or 64-bit:\r\n\r\n- Python: 3.5.2\r\n- pyodbc: 4.0.22 (issue does not happen with 4.0.21)\r\n- OS: windows 7 64-bit\r\n- DB: sql server 2014\r\n- driver: ODBC Driver 13 for SQL Server\r\n-django 1.11.9\r\n\r\nI have a model that contains a filed \"question_text\" of type TextField.\r\nWhen I try to insert something of small length (1000 char) it works fine.\r\nHowever, when I try to insert something bigger (4001 char or more) it throws an Invalid precision value error.\r\n\r\nModels\r\n```\r\nclass Question(models.Model):\r\n    question_text = models.TextField()\r\n    pub_date = models.DateTimeField()\r\n```\r\nTests\r\n```\r\nclass Tests(TransactionTestCase):\r\n    def test_text_field_fail(self):\r\n        a = 'a'*8000\r\n        q = Question(question_text=a, pub_date=datetime.datetime.now())\r\n        q.save()\r\n\r\n    def test_text_field_pass(self):\r\n        a = 'a' * 100\r\n        q = Question(question_text=a, pub_date=datetime.datetime.now())\r\n        q.save()\r\n```\r\nSettings\r\n```\r\nDATABASES = {\r\n    'default': {\r\n        'ENGINE': 'sql_server.pyodbc',\r\n\t\t'HOST': '----',\r\n        'NAME': '----',\r\n\t\t'USER': '----',\r\n\t\t'PASSWORD': '---',\r\n\t\t'OPTIONS': {'driver': 'ODBC Driver 13 for SQL Server',},\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/comments/371573010","html_url":"https://github.com/mkleehammer/pyodbc/issues/359#issuecomment-371573010","issue_url":"https://api.github.com/repos/mkleehammer/pyodbc/issues/359","id":371573010,"user":{"login":"titomisa","id":25230980,"avatar_url":"https://avatars3.githubusercontent.com/u/25230980?v=4","gravatar_id":"","url":"https://api.github.com/users/titomisa","html_url":"https://github.com/titomisa","followers_url":"https://api.github.com/users/titomisa/followers","following_url":"https://api.github.com/users/titomisa/following{/other_user}","gists_url":"https://api.github.com/users/titomisa/gists{/gist_id}","starred_url":"https://api.github.com/users/titomisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/titomisa/subscriptions","organizations_url":"https://api.github.com/users/titomisa/orgs","repos_url":"https://api.github.com/users/titomisa/repos","events_url":"https://api.github.com/users/titomisa/events{/privacy}","received_events_url":"https://api.github.com/users/titomisa/received_events","type":"User","site_admin":false},"created_at":"2018-03-08T18:08:46Z","updated_at":"2018-03-08T18:08:46Z","author_association":"NONE","body":"Django error\r\n```\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\backends\\utils.py\", line 85, in _execute\r\n    return self.cursor.execute(sql, params)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\sql_server\\pyodbc\\base.py\", line 520, in execute\r\n    return self.cursor.execute(sql, params)\r\npyodbc.Error: ('HY104', '[HY104] [Microsoft][ODBC Driver 13 for SQL Server]Inval\r\nid precision value (0) (SQLBindParameter)')\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"R:\\Personal Folders\\Alberto Misail\\Database 2.0\\Django  code\\BatteryPars\r\ner2Django2\\parserdb2\\tests.py\", line 10, in test_text_field_fail\r\n    q.save()\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\base.py\", line 729, in save\r\n    force_update=force_update, update_fields=update_fields)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\base.py\", line 759, in save_base\r\n    updated = self._save_table(raw, cls, force_insert, force_update, using, upda\r\nte_fields)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\base.py\", line 842, in _save_table\r\n    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\base.py\", line 880, in _do_insert\r\n    using=using, raw=raw)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\manager.py\", line 82, in manager_method\r\n    return getattr(self.get_queryset(), name)(*args, **kwargs)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\query.py\", line 1125, in _insert\r\n    return query.get_compiler(using=using).execute_sql(return_id)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\models\\sql\\compiler.py\", line 1283, in execute_sql\r\n    cursor.execute(sql, params)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\backends\\utils.py\", line 68, in execute\r\n    return self._execute_with_wrappers(sql, params, many=False, executor=self._e\r\nxecute)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\backends\\utils.py\", line 77, in _execute_with_wrappers\r\n    return executor(sql, params, many, context)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\backends\\utils.py\", line 85, in _execute\r\n    return self.cursor.execute(sql, params)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\utils.py\", line 89, in __exit__\r\n    raise dj_exc_value.with_traceback(traceback) from exc_value\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\django\\db\\backends\\utils.py\", line 85, in _execute\r\n    return self.cursor.execute(sql, params)\r\n  File \"C:\\Users\\alberto.misail\\AppData\\Local\\Programs\\Python\\Python35\\lib\\site-\r\npackages\\sql_server\\pyodbc\\base.py\", line 520, in execute\r\n    return self.cursor.execute(sql, params)\r\ndjango.db.utils.Error: ('HY104', '[HY104] [Microsoft][ODBC Driver 13 for SQL Ser\r\nver]Invalid precision value (0) (SQLBindParameter)')\r\n```\r\nFind attached the ODBC trace\r\n[SQL.LOG](https://github.com/mkleehammer/pyodbc/files/1794261/SQL.LOG)\r\n\r\nSchema:\r\nthe table is called dbo.parserdb2_question\r\nSo the schema would be dbo\r\n\r\n"}}
{"actor":{"display_login":"titomisa"}}