rdegges / flask-dynamo

DynamoDB integration for Flask.
http://flask-dynamo.readthedocs.org/en/latest/
The Unlicense
141 stars 36 forks source link

use GlobalSecondaryIndexes not work #35

Open simple2source opened 6 years ago

simple2source commented 6 years ago

i use boto3 or boto3 session it query mobile data,but use flask-dynamo not work ,query data is None, why ? it's my code

    from flask import current_app
    dynamo = current_app.extensions['dynamo'] 
    response = dynamo.tables[ACCOUNT_TABLE].query(IndexName='mobile-index',
                                                  KeyConditionExpression=Key('mobile').eq(mobile))
    account_data = response.get("Item")
    import boto3
    dynamodb = boto3.resource('dynamodb')
    account = dynamodb.Table(ACCOUNT_TABLE)
    resp = account.query(IndexName='mobile-index', KeyConditionExpression=Key('mobile').eq(mobile))
    print(account_data, 80*'#')
    print(resp, 80*'^')
    from boto3.session import Session
    bs = Session()
    s_dy = bs.resource('dynamodb')
    s_ac = s_dy.Table(ACCOUNT_TABLE)
    res = s_ac.query(IndexName='mobile-index', KeyConditionExpression=Key('mobile').eq(mobile))
    print(res, 80*'-')
simple2source commented 6 years ago

it's input

None ################################################################################
{'Items': [{'android_density': '3.0', 'android_densitydpi': '480.0', 'app_id_99999_register_time': Decimal('1522057214'), 'store_name': 'jinke', 'android_id': 'a0e1b09e458d678c', 'account_type': Decimal('2'), 'boot_time': '210940', 'android_ramsize': '2825134080', 'network_info': 'WIFI', 'account_name': '13873437978', 'event_id': Decimal('101'), 'android_version_code': Decimal('1550'), 'brand': 'Xiaomi', 'platform_id': Decimal('1'), 'os_version': '7.0', 'account_type_account_name': '2#13873437978', ', 'android_version_name': '1.5.5.163', 'android_imsi1': None, 'android_imei1': '862033030645103', 'screen_height': Decimal('1920'), 'bssid': '70:3d:15:e6:c3:e0','password': '112', 'mobile': '13873437978', 'sms_code': '7320', 'open_id': 'lK4bu12001uD00QGtQ42Efn0C20dnOF', 'language': 'zh', 'app_id': Decimal('99999'), 'channel_id': Decimal('2'), 'android_romsize': '57787318272', 'ua': 'Mozilla/5.0 (Linux; Android 7.0; MI 5 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36', 'group': '30', 'account': '110', 'android_imsi2': None, 'android_imei2': '862033030645111', 'screen_width': Decimal('1080'), 'os': Decimal('1'), 'account_password': '112', 'android_mah': None, 'orientation': Decimal('0'), 'model': 'MI 5', 'sdk_version': '24', 'user_ip': '127.0.0.1', 'pkg_name': 'com.outfit7.mytalkinghank', 'mac': 'B0:E2:35:CD:A6:D5', 'register_time': Decimal('1522057214'), 'android_cpu': 'AArch64 Processor rev 2 (aarch64) ', 'event_time_client': Decimal('1522057214'), 'android_sdsize': '57787318272'}], 'ScannedCount': 1, 'Count': 1, 'ResponseMetadata': {'HTTPHeaders': {'content-length': '1776', 'x-amz-crc32': '1657515183', 'content-type': 'application/x-amz-json-1.0', 'date': 'Mon, 26 Mar 2018 12:41:47 GMT', 'server': 'Server', 'connection': 'keep-alive', 'x-amzn-requestid': '1H4LNUIJKPA0MJO47MMOUR5GV7VV4KQNSO5AEMVJF66Q9ASUAAJG'}, 'HTTPStatusCode': 200, 'RequestId': '1H4LNUIJKPA0MJO47MMOUR5GV7VV4KQNSO5AEMVJF66Q9ASUAAJG', 'RetryAttempts': 0}} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{'Items': [{'android_density': '3.0', 'android_densitydpi': '480.0', 'app_id_99999_register_time': Decimal('1522057214'), 'store_name': 'jinke', 'android_id': 'a0e1b09e458d678c', 'account_type': Decimal('2'), 'boot_time': '210940', 'android_ramsize': '2825134080', 'network_info': 'WIFI', ', 'account_name': '13873437978', 'event_id': Decimal('101'), 'android_version_code': Decimal('1550'), 'brand': 'Xiaomi', 'platform_id': Decimal('1'), 'os_version': '7.0', 'account_type_account_name': '2#13873437978', ''screen_height': Decimal('1920'), 'bssid': '70:3d:15:e6:c3:e0',  'password': '112', 'mobile': '110', 'sms_code': '7320', 'open_id': 'lK4bu12001uD00QGtQ42Efn0C20dnOF', 'language': 'zh', 'app_id': Decimal('99999'), 'channel_id': Decimal('2'), 'android_romsize': '57787318272', 'ua': 'Mozilla/5.0 (Linux; Android 7.0; MI 5 Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36', 'group': '30', 'account': '13873437978', 'android_imsi2': None, 'android_imei2': '862033030645111', 'screen_width': Decimal('1080'), 'os': Decimal('1'), 'account_password': '112', 'android_mah': None, 'orientation': Decimal('0'), 'model': 'MI 5', 'sdk_version': '24', 'user_ip': '127.0.0.1', 'pkg_name': 'com.outfit7.mytalkinghank', 'mac': 'B0:E2:35:CD:A6:D5', 'register_time': Decimal('1522057214'), 'android_cpu': 'AArch64 Processor rev 2 (aarch64) ', 'event_time_client': Decimal('1522057214'), 'android_sdsize': '57787318272'}], 'ScannedCount': 1, 'Count': 1, 'ResponseMetadata': {'HTTPHeaders': {'content-length': '1776', 'x-amz-crc32': '1657515183', 'content-type': 'application/x-amz-json-1.0', 'date': 'Mon, 26 Mar 2018 12:41:48 GMT', 'server': 'Server', 'connection': 'keep-alive', 'x-amzn-requestid': 'I0JCUTITE5G8H01CDTO4TSNN5BVV4KQNSO5AEMVJF66Q9ASUAAJG'}, 'HTTPStatusCode': 200, 'RequestId': 'I0JCUTITE5G8H01CDTO4TSNN5BVV4KQNSO5AEMVJF66Q9ASUAAJG', 'RetryAttempts': 0}} --------------------------------------------------------------------------------
simple2source commented 6 years ago

i use get_item it's work

    response = dynamo.tables[ACCOUNT_TABLE].get_item(Key={'account': account_name})
    account_data = response.get("Item")

it's work alright

my flask-dynamo config:

    app.config['DYNAMO_TABLES'] = [
        dict(
            TableName=table_prefix+'account',
            KeySchema=[dict(AttributeName='account', KeyType='HASH')],
            AttributeDefinitions=[dict(AttributeName='account', AttributeType='S')],
            ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5),
            GlobalSecondaryIndexes=[
                dict(IndexName='mobile-index',
                     KeySchema=[dict(AttributeName='mobile', KeyType='HASH')],
                     Projection=dict(ProjectionType='ALL', NonKeyAttributes=['string']),
                     ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
                     )
            ]
        )
        )]

    dynamo.init_app(app)

i'm confuse >