-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on bad json. #902
Comments
Please share the full traceback and error message |
It was running in a container, this is all I have. Logfire did not log the error because it crashed. I add a bit before what I sent earlier.
|
Got a bit more detail. I have attached the offending json data. The issue is around "Kevin 'Brett\u0000 Stakelin" def sanitize_json(race_id, data):
if data is None:
return None
try:
if isinstance(data, str):
# For string representation of JSON
string = data.replace("\u0000", "")
return string
elif isinstance(data, (dict, list)):
logfire.info(f"JSON data: {data}")
# For Python objects, convert to JSON string, sanitize, then parse back
json_str = json.dumps(data)
sanitized_str = json_str.replace("\u0000", "")
json_data = json.loads(sanitized_str)
return json_data
else:
logfire.warning(f"** Non-string data or dict: {data}")
return data
except Exception as e:
logfire.exception(f"Error: {race_id}, sanitizing JSON data: {e!s}")
return None {'json_str': '[{"place": "1", "points": "245.29", "name": "Chris Hamilton", "city_state": "Denver, CO", "time": "44:03.1", "usac_number": "307709", "bib": "", "team": ""}, {"place": "2", "points": "258.67", "name": "Shawn Kingrey", "city_state": "Pueblo, CO", "time": "44:06.6", "usac_number": "167284", "bib": "", "team": ""}, {"place": "3", "points": "272.05", "name": "Bill Bottom", "city_state": "Fort Collins, CO", "time": "44:31.1", "usac_number": "363282", "bib": "", "team": ""}, {"place": "4", "points": "285.43", "name": "Kyle Link", "city_state": "Steamboat Springs, CO", "time": "44:31.1", "usac_number": "517925", "bib": "", "team": ""}, {"place": "5", "points": "298.81", "name": "Jay Paidipati", "city_state": "Superior, CO", "time": "44:41.0", "usac_number": "484498", "bib": "", "team": ""}, {"place": "6", "points": "312.19", "name": "Neal Mendel", "city_state": "Denver, CO", "time": "45:10.2", "usac_number": "286615", "bib": "", "team": ""}, {"place": "7", "points": "325.57", "name": "Robert Vester", "city_state": "Milwaukee, WI", "time": "45:28.7", "usac_number": "448238", "bib": "", "team": ""}, {"place": "8", "points": "338.95", "name": "Brent Brown", "city_state": "Denver, CO", "time": "46:12.4", "usac_number": "438302", "bib": "", "team": ""}, {"place": "9", "points": "352.33", "name": "Mike Higgins", "city_state": "Canon City, CO", "time": "46:47.4", "usac_number": "88299", "bib": "", "team": ""}, {"place": "10", "points": "365.71", "name": "Eric Falldin", "city_state": "Berthoud, CO", "time": "47:18.0", "usac_number": "243927", "bib": "", "team": ""}, {"place": "11", "points": "379.09", "name": "Kevin \'Brett\\u0000 Stakelin", "city_state": "Denver, CO", "time": "49:22.5", "usac_number": "282065", "bib": "", "team": ""}, {"place": "12", "points": "392.47", "name": "Dave DuBois", "city_state": "Fort Collins", "time": "50:45.3", "usac_number": "416557", "bib": "", "team": ""}, {"place": "13", "points": "405.85", "name": "Allan Marvin", "city_state": "Denver, CO", "time": "50:45.7", "usac_number": "22787", "bib": "", "team": ""}, {"place": "14", "points": "419.23", "name": "Cris Compton", "city_state": "Littleton", "time": "51:22.6", "usac_number": "378190", "bib": "", "team": ""}]', 'race_id': 1043765} |
One thing that is strange is I have no problem migrating to a sqlitedb, this is only a problem from postgres to postrges |
I'm not managing to reproduce a problem. This works fine: import json
import logfire
logfire.configure()
json_str = '[{"place": "1", "points": "245.29", "name": "Chris Hamilton", "city_state": "Denver, CO", "time": "44:03.1", "usac_number": "307709", "bib": "", "team": ""}, {"place": "2", "points": "258.67", "name": "Shawn Kingrey", "city_state": "Pueblo, CO", "time": "44:06.6", "usac_number": "167284", "bib": "", "team": ""}, {"place": "3", "points": "272.05", "name": "Bill Bottom", "city_state": "Fort Collins, CO", "time": "44:31.1", "usac_number": "363282", "bib": "", "team": ""}, {"place": "4", "points": "285.43", "name": "Kyle Link", "city_state": "Steamboat Springs, CO", "time": "44:31.1", "usac_number": "517925", "bib": "", "team": ""}, {"place": "5", "points": "298.81", "name": "Jay Paidipati", "city_state": "Superior, CO", "time": "44:41.0", "usac_number": "484498", "bib": "", "team": ""}, {"place": "6", "points": "312.19", "name": "Neal Mendel", "city_state": "Denver, CO", "time": "45:10.2", "usac_number": "286615", "bib": "", "team": ""}, {"place": "7", "points": "325.57", "name": "Robert Vester", "city_state": "Milwaukee, WI", "time": "45:28.7", "usac_number": "448238", "bib": "", "team": ""}, {"place": "8", "points": "338.95", "name": "Brent Brown", "city_state": "Denver, CO", "time": "46:12.4", "usac_number": "438302", "bib": "", "team": ""}, {"place": "9", "points": "352.33", "name": "Mike Higgins", "city_state": "Canon City, CO", "time": "46:47.4", "usac_number": "88299", "bib": "", "team": ""}, {"place": "10", "points": "365.71", "name": "Eric Falldin", "city_state": "Berthoud, CO", "time": "47:18.0", "usac_number": "243927", "bib": "", "team": ""}, {"place": "11", "points": "379.09", "name": "Kevin \'Brett\\u0000 Stakelin", "city_state": "Denver, CO", "time": "49:22.5", "usac_number": "282065", "bib": "", "team": ""}, {"place": "12", "points": "392.47", "name": "Dave DuBois", "city_state": "Fort Collins", "time": "50:45.3", "usac_number": "416557", "bib": "", "team": ""}, {"place": "13", "points": "405.85", "name": "Allan Marvin", "city_state": "Denver, CO", "time": "50:45.7", "usac_number": "22787", "bib": "", "team": ""}, {"place": "14", "points": "419.23", "name": "Cris Compton", "city_state": "Littleton", "time": "51:22.6", "usac_number": "378190", "bib": "", "team": ""}]'
data = json.loads(json_str)
logfire.info(f'JSON data: {data}') |
import json
import logfire
data = {"name": "Kevin \'Brett\u0000 Stakelin"}
logfire.info(f'JSON data: {data}')
/Users/vincentdavis/DEV/REPO/_GOTTS.BIKE/app_gotta_bike/.venv/lib/python3.12/site-packages/logfire/_internal/main.py:355: InspectArgumentsFailedWarning: Failed to introspect calling code. Please report this issue to Logfire. Falling back to normal message formatting which may result in loss of information if using an f-string. Set inspect_arguments=False in logfire.configure() to suppress this warning. The problem was:
No source code available. This happens when running in an interactive shell, using exec(), or running .pyc files without the source .py files.
self.log('info', msg_template, attributes, tags=_tags, exc_info=_exc_info)
/Users/vincentdavis/Applications/PyCharm Professional Edition.app/Contents/plugins/python-ce/helpers/pydev/pydevconsole.py:364: FormattingFailedWarning:
Ensure you are either:
(1) passing an f-string directly, with inspect_arguments enabled and working, or
(2) passing a literal `str.format`-style template, not a preformatted string.
See https://logfire.pydantic.dev/docs/guides/onboarding-checklist/add-manual-tracing/#messages-and-span-names.
The problem was: The field {'name'} is not defined.
coro = func()
15:54:30.967 Failed to introspect calling code. Please report this issue to Logfire. Falling back to normal message formatting which may result in loss of information if using an f-string. Set inspect_arguments=False in logfire.configure() to suppress this warning. The problem was:
No source code available. This happens when running in an interactive shell, using exec(), or running .pyc files without the source .py files.
15:54:30.968 JSON data: {'name': "Kevin 'Brett\x00 Stakelin"} |
That's a different problem. I'm guessing you ran that code in an interactive shell/console? |
Those errors come from directly logging a dict object instead of a string, i.e. |
Description
I am migrating data between two postgres db's one has native JSON field the other is using Djangos JSON fields.
I am getting errors related to converting /U0000.
I tried to log the json with logfire and logfire crashed.
Python, Logfire & OS Versions, related packages (not required)
The text was updated successfully, but these errors were encountered: