question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON Value Assignment Broken in v0.7.3

See original GitHub issue

With the release of v0.7.3 we are seeing a number of failures with the following error when attempting to assign values to JSON properties on our models.

src\app\lib\db_store.py:134: in update
    setattr(maint, key, val)
<string>:2: in __set__
    ???
..\..\python36-32\lib\site-packages\pony\utils\utils.py:58: in cut_traceback
    return func(*args, **kwargs)
..\..\python36-32\lib\site-packages\pony\orm\core.py:2120: in __set__
    new_val = attr.validate(new_val, obj, from_db=False)
..\..\python36-32\lib\site-packages\pony\orm\core.py:2352: in validate
    val = Attribute.validate(attr, val, obj, entity, from_db)
..\..\python36-32\lib\site-packages\pony\orm\core.py:2027: in validate
    val = converter.validate(val, obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

converter = <pony.orm.dbproviders.sqlite.SQLiteJsonConverter object at 0x0453C750>
val = {}, obj = OurModel['000000000000000000']

    def validate(converter, val, obj=None):
        if obj is None or converter.attr is None:
            return val
>       if isinstance(val, TrackedValue) and val.obj is obj and val.attr is converter.attr:
E       AttributeError: 'TrackedDict' object has no attribute 'obj'

Looking at the code, it appears that this was introduced as part of the fix for #283 and is simply a matter of the wrong property being used here to reference this.

Code that generates this error

from pony import orm
from pony.orm import db_session
from uuid import uuid4

db = orm.Database()
class OurModel(db.Entity):
  id = orm.PrimaryKey(str, default=lambda: uuid4().hex)
  data = orm.Required(orm.Json)

id = uuid4().hex
with db_session:
  # This is OK
  entity = OurModel(id=id, data={})
  db.commit()

with db_session:
  entity = OurModel[id]
  entity.data = {"test": True} # This throws an exception

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Vitaliumcommented, Nov 12, 2017

That’s not all. There is another related bug. While trying to change loaded entity object several times, it is raised exception: pony.orm.dbapiprovider.InterfaceError: Error binding parameter ## - probably unsupported type.

There is a workaround - to set Json field volatile.

I’m trying now to write a code to reproduce this issue and add it later.

0reactions
steellibertycommented, Jan 18, 2018

I am getting InterfaceError: Error binding parameter 2 - probably unsupported type. Error binding parameter 2 - probably unsupported type.

with version 7.3 while running 7.2 mode code runs without and error.

I am doing a Json assignment – This is happening in numerous places in the code – but for example the simplest case is :

class NewsFeeds(newsfeeds.Entity): id = PrimaryKey(int, auto=True) feedinfo = Optional(Json, default = {}) hashlist = Optional(Json, default=[]) feedlist = Optional(Json, default = {}) feeds = Optional(Json, default = {})

@classmethod @db_session def addHashCode(cls,h): nf = NewsFeeds.get(id=1) if nf: nf.hashlist.append(h) commit()

The same code in 7.2 works everytime … there are other places that blow up in the full code – sometimes the assignment above works but then later another one fails.

I can see nothing that explains this …

Any thoughts ? (note proper code indentation changes when I save this – however the indentation is correct in the original )

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
What went wrong? JSON. parse() parses a string as JSON. This string has to be valid JSON and will throw this error if...
Read more >
PHP 7 ChangeLog
PHP 7 ChangeLog. 7.4 | 7.3 | 7.2 | 7.1 | 7.0. Version 7.4.33. 03 Nov 2022. GD: Fixed bug #81739: OOB read...
Read more >
Converting JSON data to Java object - Stack Overflow
I want to be able to access properties from a JSON string within my Java action method. The string is available ...
Read more >
Welcome to Python.org
The official home of the Python Programming Language.
Read more >
Generating JSON data - Db2 for i SQL - IBM
By using SQL functions, you can generate formatted JSON data from ... The output for each entry is broken across two lines to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found