|
15 | 15 | from labelbox.exceptions import InvalidQueryError, LabelboxError, ResourceNotFoundError, InvalidAttributeError |
16 | 16 | from labelbox.orm.db_object import DbObject, Updateable, Deletable |
17 | 17 | from labelbox.orm.model import Entity, Field, Relationship |
| 18 | +from labelbox.orm import query |
18 | 19 | from labelbox.exceptions import MalformedQueryException |
19 | 20 |
|
20 | 21 | if TYPE_CHECKING: |
@@ -102,15 +103,35 @@ def convert_field_keys(items): |
102 | 103 | elif os.path.exists(row_data): |
103 | 104 | # If row data is a local file path, upload it to server. |
104 | 105 | args[DataRow.row_data.name] = self.client.upload_file(row_data) |
105 | | - args[DataRow.dataset.name] = self |
106 | 106 |
|
107 | 107 | # Parse metadata fields, if they are provided |
108 | 108 | if DataRow.metadata_fields.name in args: |
109 | 109 | mdo = self.client.get_data_row_metadata_ontology() |
110 | 110 | args[DataRow.metadata_fields.name] = mdo.parse_upsert_metadata( |
111 | 111 | args[DataRow.metadata_fields.name]) |
112 | 112 |
|
113 | | - return self.client._create(DataRow, args) |
| 113 | + query_str = """mutation CreateDataRowPyApi( |
| 114 | + $row_data: String!, |
| 115 | + $metadata_fields: [DataRowCustomMetadataUpsertInput!]!, |
| 116 | + $attachments: [DataRowAttachmentInput!], |
| 117 | + $media_type : MediaType, |
| 118 | + $dataset: ID! |
| 119 | + ){ |
| 120 | + createDataRow( |
| 121 | + data: |
| 122 | + { |
| 123 | + rowData: $row_data |
| 124 | + mediaType: $media_type |
| 125 | + metadataFields: $metadata_fields |
| 126 | + attachments: $attachments |
| 127 | + dataset: {connect: {id: $dataset}} |
| 128 | + } |
| 129 | + ) |
| 130 | + {%s} |
| 131 | + } |
| 132 | + """ % query.results_query_part(Entity.DataRow) |
| 133 | + res = self.client.execute(query_str, {**args, 'dataset': self.uid}) |
| 134 | + return DataRow(self.client, res['createDataRow']) |
114 | 135 |
|
115 | 136 | def create_data_rows_sync(self, items) -> None: |
116 | 137 | """ Synchronously bulk upload data rows. |
|
0 commit comments