# How to apply udf modules

**URL:** <https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075>\
**Category:** Python Client\
**Created:** [March 20, 2015, 6:40am UTC](https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075 "2015-03-20T06:40:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pooja123](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@pooja123](https://discuss.aerospike.com/u/pooja123)\
**Post date:** [March 20, 2015, 6:40am UTC](https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075/1 "2015-03-20T06:40:12Z")

</div>

which software we need to run lua modules for aerospike python client. how to debug

```
Exception: (100L, "/opt/aerospike/usr/udf/lua/pooja.lua:3: bad argument #1 to 'append' (userdata expected, got string)", 'src/main/aerospike/as_command.c', 730)

```

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [May 15, 2015, 8:23pm UTC](https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075/2 "2015-05-15T20:23:31Z")

</div>

That message means that there’s a bug in your Lua code. Please provide a sample of your code.

---

<div class="post-metadata">

**Author:** ![pooja123](https://avatars.discourse-cdn.com/v4/letter/p/fbc32d/32.png) [@pooja123](https://discuss.aerospike.com/u/pooja123)\
**Post date:** [May 16, 2015, 11:11am UTC](https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075/3 "2015-05-16T11:11:46Z")

</div>

```
function list_append(rec, bin, value)
  local l = rec[bin]
  list.append(l, value)
  rec[bin] = l
  aerospike:update(rec)
  return 0
end

```

this is my lua code

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [May 17, 2015, 12:31am UTC](https://discuss.aerospike.com/t/how-to-apply-udf-modules/1075/4 "2015-05-17T00:31:47Z")

</div>

Hi Pooja,

The error message you’re seeing will come up whenever you try to perform list operations on a bin holding a value that is not a list. I’m starting out with a new record that has three bins, two hold integer values and one holds a list:

```sql
aql> select * from test.demo where PK='key2'
+---+----+----------+
| b | id | z |
+---+----+----------+
| 2 | 2 | ["z", 2] |
+---+----+----------+
1 row in set (0.000 secs)

```

I call your script on the bin ‘z’ once:

```python
client.apply(('test','demo','key2'), 'x', 'list_append', ['z',4])

```

Which results in:

```sql
aql> select * from test.demo where PK='key2'
+---+----+-------------+
| b | id | z |
+---+----+-------------+
| 2 | 2 | ["z", 2, 4] |
+---+----+-------------+
1 row in set (0.000 secs)

```

Now I’ll try to invoke append\_list on bin ‘b’ which is an integer:

```python
client.apply(('test','demo','key2'), 'x', 'list_append', ['b',5])

```

And the following error is triggered:

```auto
Error (100L, "/opt/aerospike/usr/udf/lua/x.lua:3: bad argument #1 to 'append' (userdata expected, got number)", 'src/main/aerospike/as_command.c', 731)

```

So, I suggest adding a test for whether the operation is safe to perform inside the Lua module:

```nohighlight
function list_append(rec, bin, value)
    local l = rec[bin]
    if type(l) == 'number' or type(l) == 'string' then
        return nil
    end
    if (tostring(getmetatable(rec[bin])) == tostring(getmetatable(list()))) then
        list.append(l, value)
        rec[bin] = l
        aerospike:update(rec)
        return l
    end
    return nil
end

```
