【SQL Alchemy】AttributeError: '...' object has no attribute 'translate'错误的解决
bug情境描述
经过查找,SQL Alchemy没有自带ON DUPLICATE KEY UPDATE功能,所以打算手写一个。于是产生了下面的(错误)脑洞…
先按照想要UNIQUE的列查出结果,然后判断:
- 如果查询有结果,就用新Object的所有列去替换原有Object的所有列
- 如果查询无结果,就直接db.session.add这个Object
以上方式没有考虑到新的Object可能有些属性(列)没有值(大概是None?或者Null?),直接赋值给旧的Object的话,可能在存储的时候,类型会有问题。所以直接替换每一个属性可能不是好方法,或者需要判断一下是否为空,再给新的Object赋值才可以。
想了一个替代方案:
判断如果有查询结果的话,直接删除原有的Object,然后add整个新Object:
【SQL Alchemy】AttributeError: '...' object has no attribute 'translate'错误的解决相关推荐
- Spyder 运行出现 Reloaded modules: **AttributeError: 'NoneType' object has no attribute 'modules' 错误的解决方法
问题描述: 刚开始学习python,有很多问题不懂,网上找了很久找不到答案,就把这个问题记下来,希望可以帮助到其他初学者 使用spyder运行以下代码: 第一次运行可以正常显示结果,第二次运行时报错: ...
- Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
AttributeError: 'NoneType' object has no attribute 'backend'. 错误原因: 选择的应用后端类型不对. windows 上应用的后端类型有两种 ...
- Python 中 AttributeError: ‘NoneType‘ object has no attribute ‘X‘ 错误
文章目录 AttributeError: 'NoneType' object has no attribute 'X' 介绍 AttributeError: 'NoneType' object has ...
- keras2onnx转换时出现AttributeError: ‘KerasTensor‘ object has no attribute ‘graph’错误
[问题] keras2onnx转换时出现AttributeError: 'KerasTensor' object has no attribute 'graph'错误 File "D:\co ...
- ‘str‘ object has no attribute ‘get‘ 错误解决方案
'str' object has no attribute 'get' 错误解决方案 参考文章: (1)'str' object has no attribute 'get' 错误解决方案 (2)ht ...
- 关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法
关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法 参考文章: (1 ...
- python爬虫数据寻找过程(解决爬虫异步导致AttributeError: 'NoneType' object has no attribute 'find_all'错误)
前边写了url的分析 我们爬取想要的数据,一般是打开网站链接,用浏览器的elements功能对网页标签进行数据分析,确定想要的数据的位置,再在代码中通过requests库的get和post方式发起请求 ...
- 初学Python,遇到AttributeError: 'Person' object has no attribute 'firstname'问题的解决方法
最近在学习Python的类和对象内容时,尝试一个关于Person类的代码,出现一个问题:AttributeError: 'Person' object has no attribute 'firstn ...
- python object has no attribute_Python中出现AttributeError: object has no attribute
按照书上的编写的一个python的飞船游戏 代码也都是按照书上的编写的 但就不知道问题出在哪里 AttributeError: 'Ship' object has no attribute 'bull ...
最新文章
- 在 OS X 中使用 OpenResty
- keras 提取某一层的feature_map
- C++接口工程实践:有哪些实现方法?
- Tomcat源码解析六:Tomcat类加载器机制
- Android:日常学习笔记(8)———探究UI开发(5)
- java Switch里面的类型问题
- Android基于Glide的二次封装,借鉴Glide思想二次封装Fresco
- Ubuntu环境变量添加的安全方法
- 重构:改善既有代码的设计 精彩书评一
- 翻译:您在Swift 5中的第一个UITest
- hp 服务器 sd卡作用,用4张卡聊一聊SD卡规范
- 汉诺塔问题解析(C语言)
- JPEG 原理分析及 JPEG 解码器的调试
- Centos7.2 eclipse使用CGAL求主骨架
- 301. 删除无效的括号【我亦无他唯手熟尔】
- 运动蓝牙耳机选什么类型、蓝牙运动耳机推荐
- 更专业的过等保服务,华为云等保合规解决方案值得选择!
- 【python】pandas库pd.to_excel操作写入excel文件参数整理与实例
- js如何运行python代码_手把手教你如何使用Python执行js代码
- 苹果xr黑屏转圈圈解决方法_苹果iPhone XR升级iOS 12.3后黑屏转圈圈怎么办?附解决办法...
热门文章
- HDU - 3360 National Treasures(最小点覆盖-二分图最大匹配+奇偶拆点)
- CodeForces - 432D Prefixes and Suffixes(KMP的next数组性质)
- sqlite java blob_【转】好东西!sqlite3中BLOB数据类型存储大对象运用示例
- 16.IDA-列出函数中存在的全部call
- 2.IDA-数据显示窗口(反汇编窗口、函数窗口、十六进制窗口)
- 给网游写一个挂吧(三) – 启动外挂下
- TCP的三次握手建立连接和四次握手释放连接
- 第03讲. 原理探究,了解爬虫的基本原理
- 感谢有你 | LiveVideoStackCon 2020 北京站优秀出品人、讲师与志愿者
- 音视频技术开发周刊 73期