Prasanna
Prasanna

Reputation: 79

sqlalchemy.exc.DataError while executing the update query in Postgresql

I am trying to write a simple flask application where I am using a Postgresql as database. I am trying to update the table row on button click but it is giving me following error

DataError: (psycopg2.DataError) invalid input syntax for integer: "125/" LINE 1: ...ATE tasks SET taskname='IamUpdated' WHERE tasks.uid = '125/' ^ [SQL: 'UPDATE tasks SET taskname=%(taskname)s WHERE tasks.uid = %(uid_1)s'] [parameters: {'taskname': 'IamUpdated', 'uid_1': u'125/'}]

I am not sure if it is adding "/" at the end as a glitch or it is supposed to be like that? or That is what causing an error. Please Help.

Following is my Flask Python code

edituser = request.form.getlist('editId')
        if edituser:
            for e in edituser:
                User.query.filter_by(uid=e).update(dict(taskname="IamUpdated"))
            db.session.commit()
            return render_template("index.html",User=User.query.all())

Following is my HTML code

<form action="" method="POST">

    <div ng-controller="myctrl" >

     <table>
        <caption> Todo List</caption>
            <thead>
                <tr>
                    <td>
                        <input type="text" name="text">
                        <input type="submit"  value="Add Task" >

                    </td><td>
                    Search :<input type="text"> 

                    </td>
                </tr>
                <tr>
                    <th>Task Id</th>
                    <th>Task</th>
                </tr>
            </thead>

            <tbody>

                {% for user in User %}
                <tr>
                    <td> {{ user.uid }} </td>
                    <td >{{ user.taskname }} 
                        <input type="image" class="deleteImg" src="static/img/trash_can.png" height="15px" width="18px" name="removeId" value={{user.uid}} /> 
                         <input type="image" src="static/img/editbtn.svg"  height="15px" width="18px" name="editId" value={{user.uid}}/>

                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    <script>

    var app = angular.module("app", ['xeditable']);
    app.controller('myctrl', function($scope) {
    $scope.myname="Howdy";       
    });
    app.config(function($interpolateProvider) {
        $interpolateProvider.startSymbol('//').endSymbol('//');
    });

    app.run(function(editableOptions) {
        editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
    });
    </script>  
 </form> 
</body>

Upvotes: 0

Views: 706

Answers (2)

Shadow
Shadow

Reputation: 9427

Your problem seems to be this tag here:

<input type="image" src="static/img/editbtn.svg"  height="15px" width="18px" name="editId" value={{user.uid}}/>

All values in html are strings. Therefore they must all be quoted.

value="{{user.uid}}"

Once you've done this, HTML will know exactly what you meant to include in the value, rather than guessing.

The reason this hasn't affected other fields is because this is the only time you didn't put a space between the value and the number.

Upvotes: 1

Prasanna
Prasanna

Reputation: 79

The error was because I have "/>" at the end of the input tag. it was unnecessary. I have removed it and now it is working fine.

Upvotes: 0

Related Questions