dav: Postgresql Backend: invalid input syntax for type bytea

I’m trying to store a calendar event. The macOS client Calendar receives a 500 server error shows that it had a problem in process CalDAVWriteEntityQueueableOperation.

I did install a proxy to investigate the data the is transmitted, and I can see that the server responds with this XML data:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:sabredav-version>3.2.0</s:sabredav-version>
  <s:exception>PDOException</s:exception>
  <s:message>SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bytea</s:message>
</d:error>

There is not error inside the PHP error log. Unfortunately I cannot provide the full event data and for now I’m not able to reproduce it with a minified example. This is somehow a censored request:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.12.1//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND:20161205T151500Z
LAST-MODIFIED:20161123T115407Z
ORGANIZER;CN="XXXXXX";SCHEDULE-AGENT=CLIENT:mailto:XXXXXXXXX@XXXXXXXXXXXX
 XXXXXXXXX
UID:XXXXXXXXXXXXXXXXXXXXXXXXXXX@XXXXXXXXX
DTSTAMP:20161129T161928Z
LOCATION:XXXXXXXXX
DESCRIPTION:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
STATUS:CONFIRMED
SEQUENCE:0
SUMMARY:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
DTSTART:20161205T143000Z
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
CREATED:20161123T114949Z
ATTENDEE;CN="XXXXXXXXXXXXXX";CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROL
 E=REQ-PARTICIPANT;RSVP=TRUE;X-NUM-GUESTS=0:mailto:XXXXXXXXXXXXXXXXXXX
ATTENDEE;CN="XXXXXXXXXXX";CUTYPE=INDIVIDUAL;PARTSTAT=NEEDS-ACTION;ROLE=R
 EQ-PARTICIPANT;RSVP=TRUE;X-NUM-GUESTS=0:mailto:XXXXXXXXXXXXXXXXXXXXXXXXX
 X
END:VEVENT
END:VCALENDAR

In the database schema I can find multiple usages for the bytea type. Is there any way to further help you to debug it?

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm that this works. I did apply these changes to the database structure:

ALTER TABLE cards ALTER COLUMN carddata TYPE TEXT;
ALTER TABLE propertystorage ALTER COLUMN value TYPE TEXT;
ALTER TABLE calendarobjects ALTER COLUMN calendardata TYPE TEXT;
ALTER TABLE schedulingobjects ALTER COLUMN calendardata TYPE TEXT;

Would it make sense to create a pull request for this?

I guess I figured it out myself. Here’s what I needed.

ALTER TABLE cards ALTER COLUMN carddata TYPE TEXT USING convert_from(carddata, 'utf8') etc.

This is still a problem and the solution is to not use bytea columns in postgres but rather to use text columns.