Code Monkey home page Code Monkey logo

Comments (3)

mkdir700 avatar mkdir700 commented on May 20, 2024

批量入库时,确实是以这一批数据的第一条作为 “模板”。
对于临时解决这个问题,则需要对每个字段都进行赋值,即使是None
eg:

item = Item()
item.create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
if 'hhh' in response.text:
    item.status = 1
    item.key_a = response.xpath('...')
    item.key_b = response.xpath('...')
    item.key_c = response.xpath('...')
else:
    item.status = 0
    item.key_a = None
    item.key_b = None
    item.key_c = None

from feapder.

Boris-code avatar Boris-code commented on May 20, 2024

image
你好,我在使用框架的时候遇到这样一个现象,可能会是一个潜在的隐患
我是直接在解析体里实例化Item,然后给Item的各个键赋值。
整个解析体会有一些条件分支,如下示例代码所示
一开始我没有注意到,因为大部分情况和我料想的一样
else语句里没有赋值的字段都是自动填充None到数据库的
但是后来发现,有的数据本来key_a, key_b, key_c需要有值的,实际上却只有一个status字段的值是1,其余均为空
定位到上面那张图的代码位置
原因我猜想是这样的,多条数据在一起入库,生成sql语句的时候,选择了列表中第一条记录的key,而第一条记录的key如果是else条件下赋值的,就会只有一个字段被使用,那么这一批一起入库的数据就只有一个字段入库了
不知作者能不能明白我的意思哈哈~

item = Item()
item.create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
if 'hhh' in response.text:
    item.status = 1
    item.key_a = response.xpath('...')
    item.key_b = response.xpath('...')
    item.key_c = response.xpath('...')
else:
    item.status = 0

懂你意思,这个问题我也遇到过。同一批数据入库时,如果key不一样就会有问题。之所以没修复,是因为可以在用的层面注意下就行了。如果框架处理这个,需要遍历每一条数据,把数据按照key归类,当时觉得浪费效率,就没做这个处理。不过现在开源了,用户多了,为了使用体验,后面也可以考虑处理下

from feapder.

QinJun-1998 avatar QinJun-1998 commented on May 20, 2024

嗯确实确实,这个用的时候注意下可以解决,不过第一次用确实容易踩坑而且不太容易察觉哈哈。这个框架真棒,希望越来越好!

from feapder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.